[postgis-users] Getting x km of a linestring expressed in projection (3857)

Mike Toews mwtoews at gmail.com
Tue Nov 25 16:55:40 PST 2014


Hi Dave,

To use normalized distances between [0 1], rather than absolute
distances between [0 length], divide your LRS distance by the total
length. So for example, finding the first 2 km of a 10 km linestring:

SELECT ST_AsEWKT(ST_Line_Substring(geom, 0.0, 2 * 1000 / ST_Length(geom)))
FROM (SELECT 'SRID=3857;LINESTRING(0 0, 10000 0)'::geometry AS geom) AS f;

            st_asewkt
----------------------------------
 SRID=3857;LINESTRING(0 0,2000 0)
(1 row)

-Mike

On 26 November 2014 at 11:53, Dave Potts <dave.potts at pinan.co.uk> wrote:
>
> I like to extra the first x km from a linestring geometry with an srid id of
> 3857, but I having problems working out how to do it.
>
> I known its possible to split  a line using st_lineSubString, but that only
> works in fractions off a length,  I am interested in get it projection unit
> lengths, are there any better suggestions??
>
> Dave.


More information about the postgis-users mailing list