SHAPEFILE.GetClosestSnapPosition returns wrong shapeindex

hi. i am using vb.net and mapwingis 5.2. i need to know closest shape to a point and coordinate of nearest point on shape by using shapefile.GetClosestSnapPosition(x, y, MaxDistance,byref shapeindex, byref newX, byref newY, byref Distance). Distance & newX & newY works properly but ShapeIndex always returns -1.

Hello @ahmoradpour and welcome.

I’m sorry, but I looked at the source code, and this is a relatively new function that someone added, and is not fully implemented. It is returning -1 because it is initialized to -1 and never set to the resulting shape index. But there are other problems in this method as well, so it is not a one-line fix; I’ll have to do some debugging to resolve it.

Can you use GetClosestVertex? I understand that this may not be what you’re looking for, but perhaps it will help in the interim.

Regards,
Jerry.

1 Like

shapefile.GetClosestVertex also returns Wrong ShapeIndex in first/last vertex of a PolyLine if polylines are sequentially attached.

1 Like