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.
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;
}
}