Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
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
up vote 1 down vote accepted

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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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