I have a feature class containing several polygons. I would like to find all polygons that have a common border to a polygon of my choice. This can be done with the ISpatialFilter and esriSpatialTouches. This is known as the queen contiguity. However, the rook contiguity does not contain the polygons, which have only a point in common. It seems that this is something I can not figure out with the DE-9IM.

My idea is to test all polygons which touches my selected polygon with the Intersect method from the ITopologicalOperator interface and see if the result is from the type Point. If this is the case I have to remove this polygon.

Is there a better way to achieve this?

  • 1
    If you do not necessarily want to develop, you may want to look at the Polygon Neighbors tool where I think polygons with your rook contiguity are referred to as node neighbours. – PolyGeo Jan 3 '13 at 2:54
  • That won't work for me. I have to customize everything. – steffan Jan 3 '13 at 6:11
  • 3
    Why exactly won't it work for you? You could join the output table to your input feature class (or just use it as a lookup table) and proceed from there. – blah238 Jan 3 '13 at 6:32
  • You can certainly post your code as an answer and accept if that's what works for you. It will be more useful for other readers that way. – blah238 Jan 4 '13 at 2:08
  • I don't know if there is something like a in memory table, but the path in the example is not even thinkable. Another point is that I need this test for over 500 polygons and I don't think that the table and join overhead will be fast enough. – steffan Jan 4 '13 at 2:12

The following code works for me.

private IDictionary<int, List<int>> BuildDictioninaryOfRookContiguity()
        IDictionary<int, List<int>> neighborDictionary = new Dictionary<int, List<int>>();

        using (ComReleaser comReleaser = new ComReleaser())
            IFeatureCursor featureCursor = (IFeatureCursor)_featureClass.Search(null, false);


            IFeature currentFeature;
            while ((currentFeature = featureCursor.NextFeature()) != null)
                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry = currentFeature.Shape;
                spatialFilter.GeometryField = _featureClass.ShapeFieldName;
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelTouches;

                ISelectionSet selectionSet = _featureClass.Select(spatialFilter,
                    esriSelectionOption.esriSelectionOptionNormal, null);

                ITopologicalOperator topologicalOperator = (ITopologicalOperator) currentFeature.Shape;

                List<int> neighborIDs = new List<int>(selectionSet.Count);

                IEnumIDs enumIDs = selectionSet.IDs;

                int ID = enumIDs.Next();

                while (ID != -1)
                    IPointCollection pointCollection = (IPointCollection) topologicalOperator.Intersect(_featureClass.GetFeature(ID).Shape, esriGeometryDimension.esriGeometry0Dimension);

                    if(!(pointCollection.PointCount == 1))

                    ID = enumIDs.Next();

                neighborDictionary.Add(currentFeature.OID, neighborIDs);                 

        return neighborDictionary;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.