ST_LineMerge

更新时间:
复制 MD 格式

Merges the line elements of a MultiLineString by joining them at shared endpoints.

Syntax

geometry ST_LineMerge(geometry amultilinestring)

Parameters

ParameterDescription
amultilinestringThe geometry object to merge.

Description

ST_LineMerge joins line elements at their shared endpoints.

The function accepts MultiLineString and LineString objects. For any other geometry type, it returns an empty GeometryCollection.

Warning

ST_LineMerge deletes the M coordinates of MultiLineString objects.

Examples

Basic merge

Two line segments sharing an endpoint are joined into a single LineString.

SELECT ST_AsText(ST_LineMerge(ST_GeomFromText('MULTILINESTRING((1 1,2 1),(2 1,2 2))')));

Output:

        st_astext
-------------------------
 LINESTRING(1 1,2 1,2 2)
(1 row)