Closed joebarton3301 closed 1 year ago
You're right, this is a numerical precision issue. The computation of a point along a line segment perpendicular to another offset point is unavoidable subject to numerical roundoff. So there's basically no way to guarantee that the result of nearest points always lies within the input geometries.
Really the issue lies with the intersects
predicate. It would be nice if the predicate accepted a tolerance value, below which geometries would be considered to intersect. This is planned for future release (but no timeline yet).
As a workaround, you can compute the distance between geometries, and if it is less than the desired tolerance value consider that the geometries interesect.
I would expect coordinates returned by this method to always be covered by their respective input geometries, but I've found that's not true.
Here's an example:
I assume this is just a floating point math precision issues as I see that nearestPoints is attempting to project the input point onto the input geometry's line segments. I've been dealing with it by reducing the input geometry by a small amount to guarantee that any nearest point calculations will fall within the geometry.
I don't see anywhere that nearestPoints make such a guarantee, but the behavior seems off and the workaround is a bit awkward. Is there a better way to approach this, or is it worth considering as a change to nearestPoints?