<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 4, 2020 at 8:46 AM Martin Davis <<a href="mailto:mtnclimb@gmail.com">mtnclimb@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">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.</div></blockquote><div><br></div><div>I just realized that ST_Snap does a nice job of inserting close points into LineStrings in a single step:</div><div><br></div><div>SELECT ST_AsText( ST_Snap( <br>  'LINESTRING (1 2, 1 5, 1 9)',<br>  'POINT (1 3)',<br>  0.1<br>));<br></div><div><br></div><div>I have updated the GISSE posts (including this one [1] about snapping to multiple points).</div><div><br></div><div>It would still be useful to be able to get the segment index for other use cases.</div><div><br></div><div>[1]  <a href="https://gis.stackexchange.com/questions/41162/adding-multiple-points-to-a-linestring-in-postgis/370537#370537">https://gis.stackexchange.com/questions/41162/adding-multiple-points-to-a-linestring-in-postgis</a></div></div></div>