ThinkGeo.com    |     Documentation    |     Premium Support

Closet point to edge of shape?

Is there a function to get the closest point on a shape’s edge from another point? I looked at .GetClosestPointTo(), but that returns null if the shape is a polygon and the target point is inside/intersects. It’s fine if the target point is outside of the polygon.

For some context, I’m letting users move shapes in the edit layer by clicking and the shape moves to click point. However, they want to keep the click-on-edge to add a vertex built-in functionality.

Also, I looked at maybe using the EditOverlay’s VertexAdding and VertexAdded events, but they fire off even when a vertex is not added.

Using v13.1.2

Hi, Dan

The best long-term solution would be for the SDK to support this directly for points inside a polygon. We’ll make a note of this and consider adding it in a future update.

In the meantime, one workaround is to take all the vertices from the polygon’s outer ring and create a LineShape from them. Then you can use GetDistanceTo to calculate the shortest distance from the clicked point to that line. If you also need the exact closest point on the polygon edge, you can call polyline.GetClosestPointTo(point) .

Also, the bug ( VertexAdding and VertexAdded are fired off even when a vertex is not added) has been fixed in the latest version.

Thanks,
Ben

Thanks Ben! Using GetDistanceTo will be fine then, just wanted to make sure I wasn’t missing some built-in capability at the moment.

You are always welcome!