How can I find the closest edge point to a given point X, where X is a point either on the edge or at a vertex of a polygon? There are lots of answers and ways of finding this for points inside polygons, but I'm looking to find an answer for edge to edge.

2 Examples:

  1. I want to find the closest point on the polygon perimeter from vertex E
  2. I want to find the closest point on the polygon perimeter from random point on the DE line.

Note: neither of the closest points in this example are on the same edge as either of the two points given, but easily could be in another example.

I'm currently using the Shapely python library for all of my other calculations, but cannot seem to find any way to get to this kind of solution.

enter image description here

  • 2
    $\begingroup$ The closest point on the perimeter to vertex E is vertex E. There must be some additional condition you're leaving out. $\endgroup$ – saulspatz Feb 12 '19 at 16:31
  • $\begingroup$ Hmm. I'm trying to think of another way to explain the condition. The closest point that is not the same point, and not on the same line. But it could be the next vertex. So the closest point to point C would be point D $\endgroup$ – bentedder Feb 12 '19 at 16:40
  • $\begingroup$ If point B did not exist, then closest point to the red dot between D and E would be vertex E $\endgroup$ – bentedder Feb 12 '19 at 16:40
  • $\begingroup$ Remove the segment the point is laying on (the two segments if it is a vertex). Draw the circle to the nearest remaining vertex, and find the closest point on the intersection of the segments with the circle. $\endgroup$ – N74 Feb 12 '19 at 17:57

Assuming you know the point's coordinates and which line segment (or segments, if it's a vertex) the point is located on, you just need to calculate the minimum distance from the point to each remaining line segment. You can see how to calculate this minimum distance here. The minimum of these minimums will then be the closest point.

  • $\begingroup$ Building on this comment, because I was using Shapely I was able to do convert my polygon into a LineString and then do the following: line.interpolate(line.project(point)). Getting the length of the line is all that's left. Thanks! $\endgroup$ – bentedder Feb 12 '19 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.