[postgis-users] How can I split a polyline?

Markus Schaber schabi at logix-tt.com
Tue Mar 7 12:00:10 PST 2006


Hi, Fay,

Fay Du wrote:

> select NumGeometries(GeomFromText('MULTILINESTRING((1837220.875
> 330343.625,1836865.75 330348.53125,1836449.25 330363.03125,1836208.375
> 330362.59375,1836013.375 330371.375,1835626.625 330381.46875,1834513.625
> 330397.3125))',-1));
> return 1. Should it return number of points?

No, it returns 1 as your MULTILINESTRING consists of exactly one LINESTRING.

> select astext(geometryn(GeomFromText('MULTILINESTRING((1837220.875
> 330343.625,1836865.75 330348.53125,1836449.25 330363.03125,1836208.375
> 330362.59375,1836013.375 330371.375,1835626.625 330381.46875,1834513.625
> 330397.3125))',-1),1));
> Return same MULTILINESTRING. 

Ouch, this looks like a critical bug, but I cannot reproduce it here.

For me, this query correctly returns the (first and only) LINESTRING in
the MULTILINESTRING.

Which PostGIS version are you using? SELECT postgis_full_version() gives
the output.

> select astext(geometryn(GeomFromText('MULTILINESTRING((1837220.875
> 330343.625,1836865.75 330348.53125,1836449.25 330363.03125,1836208.375
> 330362.59375,1836013.375 330371.375,1835626.625 330381.46875,1834513.625
> 330397.3125))',-1),2));
> Return null.

This is correct, as there is no second LINESTRING in your MULTILINESTRING.

If you want the number of Points in the first LINESTRING of your
MULTILINESTRING, use something like:

select nPoints(geometryN(GeomFromText('MULTI....', -1), 1));

And to get the 42th Point, use

select PointN(geometryN(GeomFromText('MULTI....', -1), 1), 42);

HTH,
Markus

-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org



More information about the postgis-users mailing list