Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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 features on map, and i want to get the nearest poly-line to each one. How to write spatial query to get the nearest one.

I tried to use ISpatialFilter but i couldn't reach anything.

share|improve this question
up vote 3 down vote accepted

Don't know if this is still of interest but I got it working doing something like this: (you would just need to replace myPoint with your feature)

        IProximityOperator proximityOperator = myPoint as IProximityOperator;         
        ISpatialFilter spatialFilter = new SpatialFilterClass();
        spatialFilter.Geometry = (IGeometry)myGeometry;
        spatialFilter.GeometryField = myFeatureClass.ShapeFieldName;
        spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
        IFeatureCursor myFeatureCursor = myFeatureClass.Search(spatialFilter, false);

        while ((feature = myFeatureCursor.NextFeature()) != null)
            distance = proximityOperator.ReturnDistance(feature.Shape);

            if (distance > 0 && distance < closestDistance)
                closestFeature = feature;
                closestDistance = distance;
share|improve this answer
This only examines features that intersect the spatial filter's geometry, which is not a stated requirement. Unless there's a threshold distance, in which case you'd buffer the search feature, I don't think you should use a spatial filter at all. – Kirk Kuykendall Jul 4 '13 at 12:10

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.