[postgis-users] Find LineString segment index containing closest point?

Martin Davis 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 [1][2][3].

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...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20200804/b878c05f/attachment.html>

More information about the postgis-users mailing list