1

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.

1 Answer 1

4

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;
            }
        }
1
  • 1
    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. Commented Jul 4, 2013 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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