<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 5, 2020 at 9:38 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">Added to the wiki: <a href="https://trac.osgeo.org/postgis/wiki/UsersWikiLinearRefFunctions" target="_blank">https://trac.osgeo.org/postgis/wiki/UsersWikiLinearRefFunctions</a><div><br></div><div>It seems a bit awkward to use this as it stands for inserting a vertex in a line at the closest point.  I wonder if the function should also return the closest point itself?  (In fact, I am certain that it should if it is implemented as a native function, since that additional useful information costs very little to obtain). </div></div></blockquote><div><br></div><div>And done...  updated the wiki with a new version of the function which returns the index, distance and computed point on line.  Here it is in action, used for adding a vertex to a line:</div><div><br></div>WITH data(id, line) AS (VALUES<br>    ( 1, 'LINESTRING (0 0, 10 10, 20 20, 30 30)'::geometry )<br>),<br>loc AS (<br>  SELECT id, line, index, geom AS pt<br>    FROM data<br>    JOIN LATERAL ST_LineLocateSegment( data.line, 'POINT(15 15.1)'::geometry ) AS lls ON true<br>)<br>SELECT id, ST_AsText( ST_AddPoint( line, pt, index ) )<br><div>  FROM loc;</div><div><br></div><div>Note this is probably better done using ST_Snap, but sometimes it's useful to do things in a more explicit way. <br></div></div></div>