RChugunov
RChugunov

Reputation: 806

How can I extract some LINESTRING consisted of 3 or more POINTs to several LINESTRINGs each by 2 POINTs in PostGIS

I have to get an array of simple lines from one multipoint linestring. How can I do it?

Upvotes: 0

Views: 180

Answers (1)

chaos0815
chaos0815

Reputation: 801

Try this query:

SELECT MakeLine(sp,ep)
FROM (
    SELECT  pointn(wkb_geometry, generate_series(1, npoints(wkb_geometry)-1)) as sp,
            pointn(wkb_geometry, generate_series(2, npoints(wkb_geometry)  )) as ep
    FROM geom_table
  ) as tmp;

Though this isn't very performant on larger linestrings.

Upvotes: 1

Related Questions