[postgis-users] Find LineString segment index containing closest point?
mtnclimb at gmail.com
Tue Aug 4 08:46:39 PDT 2020
A frequent question on GISSE is to find the LineString segment index
containing the closest point to a given point, to allow inserting the
closest point into the line using AT_AddPoint .
AFAIK there's no easy way to do this in PostGIS currently. It looks like
it requires iterating over the segments of the LineString?
The ST_ClosestPoint function (and the Linear Referencing functions) do have
the segment index information internally. It would be nice if there was an
extended version of ST_ClosestPoint which returned a record with both the
closest point and the index of the segment containing it. Or perhaps an
extended Linear Referencing function which returns the point, the segment
index, and the fractional distance along the line.
For comparison, both Turf and JTS provide similar functionality.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the postgis-users