4

I am trying to implement a search of nearest features in ArcObjects.NET (don't suggest existing tools like Near) and I use IProximityOperator.ReturnDistance to get distances between features and to select the nearest one.

However, I've found that sometimes this method returns incorrect results.

Here is test map with one point layer (in general type of geometry is arbitrary):

Test Data.

Look at the feature with OID = 18. You can see that the nearest point is a feature with OID = 40 but the result of IProximityOperator.ReturnDistance for this feature is greater than for feature with OID = 22.

What am I doing wrong?

Test code:

var f18 = featureClass.GetFeature(18);
var f22 = featureClass.GetFeature(22);
var f40 = featureClass.GetFeature(40);

var f18AsProximityOp = (IProximityOperator)f18.Shape;

var d18_22 = f18AsProximityOp.ReturnDistance(f22.Shape);
var d18_40 = f18AsProximityOp.ReturnDistance(f40.Shape);

But d18_22 < d18_40. I use ArcGIS 10.2, .NET 3.5, Windows 7.

0

1 Answer 1

4

I downloaded your test data and was able to replicate the issue in VBA. I believe the issue is to do with the coordinate system your data is in, it is in WGS84. It seems that this Interface works only with datasets that are projected, a discussion is found in GeoNet under How to get the distance in a certain unit?.

If you project your data into a coordinate system that has meters as units then this should work. Your supplied map document data frame is in UTM 43N. If I projected the data into this then run your code logic I get the expected difference 22 is further away than 40.

0

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.