Fork me on GitHub

ST_ToMultiLine

Signatures

MULTILINESTRING ST_ToMultiLine(GEOMETRY geom);
MULTILINESTRING ST_ToMultiLine(GEOMETRYCOLLECTION geom);

Description

Constructs a MULTILINESTRING from geom’s coordinates. Returns MULTILINESTRING EMPTY for Geometries of dimension 0.

Examples

SELECT ST_ToMultiLine('POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),
                                (1 1, 2 1, 2 5, 1 5, 1 1))');
-- Answer: MULTILINESTRING((0 0, 10 0, 10 5, 0 5, 0 0),
--                          (1 1, 2 1, 2 4, 1 4, 1 1))

SELECT ST_ToMultiLine(
    'GEOMETRYCOLLECTION(
       LINESTRING(1 4 3, 10 7 9, 12 9 22),
       POLYGON((1 1 -1, 3 1 0, 3 2 1, 1 2 2, 1 1 -1)))');
-- Answer: MULTILINESTRING((1 4, 10 7, 12 9),
--                          (1 1, 3 1, 3 2, 1 2, 1 1))

SELECT ST_ToMultiLine('POINT(2 4)');
-- Answer: MULTILINESTRING EMPTY
Comparison with ST_ToMultiSegments
CREATE TABLE input(poly POLYGON);
INSERT INTO input VALUES (
    'POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),
              (1 1, 2 1, 2 5, 1 5, 1 1),
              (7 1, 8 1, 8 3, 7 3, 7 1))');
SELECT ST_ToMultiSegments(poly) SEG,
       ST_ToMultiLine(poly) LINE FROM input;
-- Answer:
-- |              SEG             |               LINE              |
-- |------------------------------|---------------------------------|
-- |MULTILINESTRING((0 0, 10 0), |MULTILINESTRING                  |
-- |    (10 0, 10 6), (10 6, 0 6),|    ((0 0, 10 0, 10 6, 0 6, 0 0),|
-- |    (0 6, 0 0), (1 1, 2 1),   |    (1 1, 2 1, 2 5, 1 5, 1 1),   |
-- |    (2 1, 2 5), (2 5, 1 5),   |    (7 1, 8 1, 8 3, 7 3, 7 1))   |
-- |    (1 5, 1 1), (7 1, 8 1),   |                                 |
-- |    (8 1, 8 3), (8 3, 7 3),   |                                 |
-- |    (7 3, 7 1))               |                                 |

See also