ST_LineMerge — Return a (set of) LineString(s) formed by sewing together a MULTILINESTRING.
geometry ST_LineMerge(
geometry amultilinestring)
;
Returns a (set of) LineString(s) formed by sewing together the constituent line work of a MULTILINESTRING.
Only use with MULTILINESTRING/LINESTRINGs. If you feed a polygon or geometry collection into this function, it will return an empty GEOMETRYCOLLECTION |
Availability: 1.1.0
requires GEOS >= 2.1.0 |
Will strip the M dimension. |
SELECT ST_AsText(ST_LineMerge( ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))') ) ); st_astext -------------------------------------------------------------------------------------------------- LINESTRING(-29 -27,-30 -29.7,-36 -31,-45 -33,-46 -32) (1 row) --If can't be merged - original MULTILINESTRING is returned SELECT ST_AsText(ST_LineMerge( ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45.2 -33.2,-46 -32))') ) ); st_astext ---------------- MULTILINESTRING((-45.2 -33.2,-46 -32),(-29 -27,-30 -29.7,-36 -31,-45 -33)) -- example with Z dimension SELECT ST_AsText(ST_LineMerge( ST_GeomFromText('MULTILINESTRING((-29 -27 11,-30 -29.7 10,-36 -31 5,-45 -33 6), (-29 -27 12,-30 -29.7 5), (-45 -33 1,-46 -32 11))') ) ); st_astext -------------------------------------------------------------------------------------------------- LINESTRING Z (-30 -29.7 5,-29 -27 11,-30 -29.7 10,-36 -31 5,-45 -33 1,-46 -32 11) (1 row)