[postgis-users] segmenting a linestring geometry

Ed Linde edolinde at gmail.com
Mon Apr 2 11:30:04 PDT 2012


Thanks Nicolas. I thought there was a simple way of doing this :)

On Mon, Apr 2, 2012 at 8:22 PM, Nicolas Ribot <nicolas.ribot at gmail.com>wrote:

> 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
> >
>
> Hi,
>
> 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.
>
> Nicolas
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120402/46d63e4f/attachment.html>


More information about the postgis-users mailing list