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

Martin Davis mtnclimb at gmail.com
Tue Aug 4 09:52:34 PDT 2020


On Tue, Aug 4, 2020 at 8:46 AM Martin Davis <mtnclimb at gmail.com> wrote:

> 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.
>

I just realized that ST_Snap does a nice job of inserting close points into
LineStrings in a single step:

SELECT ST_AsText( ST_Snap(
  'LINESTRING (1 2, 1 5, 1 9)',
  'POINT (1 3)',
  0.1
));

I have updated the GISSE posts (including this one [1] about snapping to
multiple points).

It would still be useful to be able to get the segment index for other use
cases.

[1]
https://gis.stackexchange.com/questions/41162/adding-multiple-points-to-a-linestring-in-postgis
<https://gis.stackexchange.com/questions/41162/adding-multiple-points-to-a-linestring-in-postgis/370537#370537>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20200804/0f8a0636/attachment.html>


More information about the postgis-users mailing list