Name

ST_LineMerge — Returns a LineString as a result of merging a MultiLineString.

Synopsis

geometry ST_LineMerge(bytea Geometry);

Alias

LineMerge

Description

Returns a LineString as a result of merging a MultiLineString. If the geometry can't be merged, original MultiLineString is returned.

[Note]

This function supports GeometryCollections. If the incoming geometry is a Polygon, it will return its exterior ring.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

--Connected MultiLineString
SELECT ST_AsEWKT(
 ST_LineMerge(ST_GeomFromEWKT('MULTILINESTRING ((0 0, 10 10, 20 10, 30 30),(30 30, 40 40, 50 40))')));
--Result
LINESTRING (0 0, 10 10, 20 10, 30 30, 40 40, 50 40)

--Unconnected MultiLineString
SELECT ST_AsEWKT(
 ST_LineMerge(ST_GeomFromEWKT('MULTILINESTRING ((0 0, 10 10, 20 10),(30 30, 40 40, 50 40))')) );
--Result
MULTILINESTRING ((0 0, 10 10, 20 10), (30 30, 40 40, 50 40))

--GeometryCollection
SELECT ST_AsEWKT(
 ST_LineMerge(ST_GeomFromEWKT('
    GEOMETRYCOLLECTION(MULTILINESTRING ((0 0,20 10,30 30),(30 30, 40 40)), POINT(0 0) )')));
--Result
LINESTRING (0 0, 20 10, 30 30, 40 40)

SELECT ST_AsText(ST_LineMerge(ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')));
--Result
LINESTRING (0 0, 10 0, 10 10, 0 10, 0 0)

Related functions