<div dir="ltr">Returning a record with all information is a nice extension.  Might choose a different function name, though.<div><br></div><div>And agreed, it makes more sense to make the index 0-based, to match the ST_AddPoint function.  The point index origin in PostGIS functions seems to a be bit inconsistent - or is it only ST_PointN which is different?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 5, 2020 at 8:46 AM Bruce Rindahl <<a href="mailto:bruce.rindahl@gmail.com">bruce.rindahl@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"><div dir="ltr">My two cents:<div>Since you are computing the distance, why not return it?  Also make the index zero based like most of the other st_ functions.<div><br></div><div>CREATE OR REPLACE FUNCTION ST_LineLocateN( line geometry, pt geometry )<br>RETURNS table(index integer, dist double precision)<br>AS $$<br>    SELECT i - 1, dist FROM (<br>    SELECT i, ST_Distance(<br>        ST_MakeLine( ST_PointN( line, s.i ), ST_PointN( line, s.i+1 ) ),<br>        pt) AS dist<br>      FROM generate_series(1, ST_NumPoints( line )-1) AS s(i)<br>      ORDER BY dist<br>    ) AS t LIMIT 1;<br>$$<br>LANGUAGE sql STABLE STRICT;<br></div></div></div></div>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a></blockquote></div>