Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 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

 
discard

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.