Using JTS, how to find the nearest point on a polygon's boundary from an outside point?
Asked Answered
R

1

8

Using JTS, how to find the nearest point on a polygon's boundary from an outside point?

Repugnant answered 26/11, 2010 at 7:26 Comment(0)
C
11

Check out the DistanceOp. It returns an array of Coordinates:

Coordinate[] pts = DistanceOp.closestPoints(poly, outsidePoint);

pts[0] will be the point on the first geometry (in this case the polygon) and pts[1] will be on the second geometry (so, the same outside point you just passed in).

Cradlesong answered 11/4, 2011 at 19:53 Comment(1)
The solution that says: "Eggplant Jeff" is fantastic. But the newest versions of the DistanceOP API has been marked the method "closestPoints" as "deprecated". You can use nearestPoints() instead!Premarital

© 2022 - 2025 — McMap. All rights reserved.