[postgis-users] How can I split a polyline?
Michael Fuhr
mike at fuhr.org
Tue Mar 7 11:46:17 PST 2006
On Tue, Mar 07, 2006 at 11:47:37AM -0500, Fay Du wrote:
> I still have a questions. What is a true multi-line?
MULTILINESTRING as opposed to a LINESTRING. The MULTI and
GEOMETRYCOLLECTION types represent collections of other objects;
a MULTILINESTRING is a collection of LINESTRINGs.
> 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, because this MULTILINESTRING contains one LINESTRING.
SELECT NumGeometries('MULTILINESTRING((0 0,1 1))');
numgeometries
---------------
1
(1 row)
SELECT NumGeometries('MULTILINESTRING((0 0,1 1),(2 2,3 3))');
numgeometries
---------------
2
(1 row)
> 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.
It should return a LINESTRING, not a MULTILINESTRING.
SELECT AsText(GeometryN('MULTILINESTRING((0 0,1 1),(2 2,3 3))', 1));
astext
---------------------
LINESTRING(0 0,1 1)
(1 row)
SELECT AsText(GeometryN('MULTILINESTRING((0 0,1 1),(2 2,3 3))', 2));
astext
---------------------
LINESTRING(2 2,3 3)
(1 row)
> 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.
You've requested the second geometry but this MULTILINESTRING has
only one geometry.
SELECT AsText(GeometryN('MULTILINESTRING((0 0,1 1),(2 2,3 3))', 3));
astext
--------
(1 row)
--
Michael Fuhr
More information about the postgis-users
mailing list