[postgis-users] segmenting a linestring geometry

Nicolas Ribot nicolas.ribot at gmail.com
Mon Apr 2 11:22:05 PDT 2012

On 2 April 2012 19:38, Ed Linde <edolinde at gmail.com> wrote:
> Hi All,
> I see that ST_Segmentize allows me to introduce points to a line string "x"
> meters apart. I was wondering if
> there was a way to break the line string so that I can get lines "x" meters
> in length returned as separate rows..
> all belonging to the one segment ID?
> Cheers,
> Ed


You could dump the line points and create lines from 2 consecutive
points, using st_makeline:

with points as (
	select (st_dumpPoints(line)).path[1], (st_dumpPoints(line)).geom from (
		select st_segmentize('LINESTRING(0 0, 100 100)'::geometry, 20) as line
	) as foo
) select p1.path, p2.path, st_makeline(p1.geom, p2.geom)
from points as p1, points as p2
where p1.path <> p2.path
and p2.path = p1.path+1;

One could replace the self join by a smart "group by" clause grouping
2 points together.


More information about the postgis-users mailing list