Using JTS, how to find the nearest point on a polygon's boundary from an outside point?
Using JTS, how to find the nearest point on a polygon's boundary from an outside point?
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).
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.