Returning a record with all information is a nice extension. Might choose a different function name, though.
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? On Wed, Aug 5, 2020 at 8:46 AM Bruce Rindahl <[email protected]> wrote: > My two cents: > Since you are computing the distance, why not return it? Also make the > index zero based like most of the other st_ functions. > > CREATE OR REPLACE FUNCTION ST_LineLocateN( line geometry, pt geometry ) > RETURNS table(index integer, dist double precision) > AS $$ > SELECT i - 1, dist FROM ( > SELECT i, ST_Distance( > ST_MakeLine( ST_PointN( line, s.i ), ST_PointN( line, s.i+1 ) ), > pt) AS dist > FROM generate_series(1, ST_NumPoints( line )-1) AS s(i) > ORDER BY dist > ) AS t LIMIT 1; > $$ > LANGUAGE sql STABLE STRICT; > _______________________________________________ > postgis-users mailing list > [email protected] > https://lists.osgeo.org/mailman/listinfo/postgis-users
_______________________________________________ postgis-users mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/postgis-users
