Fork me on GitHub

ST_Length

Signature

DOUBLE ST_Length(GEOMETRY linestring);

Description

Returns the length of (multi)Linestring.

Length is measured in the units of the spatial reference system.

Note that (multi)points, (multi)polygons or GeometryCollections return 0.0.

Implements the OpenGIS Simple Features Implementation Specification for SQL version 1.2.1.

Examples

SELECT ST_Length('LINESTRING(2 1, 1 3, 5 2)');
-- Answer: 6.35917360311745

SELECT ST_Length('MULTILINESTRING ((1 1, 1 2, 2 2),
                                   (2 1, 3 1, 3 3))');
-- Answer: 5
Cases where ST_Length returns 0
SELECT ST_Length('MULTIPOINT((4 4), (1 1), (1 0), (0 3)))');
-- Answer: 0.0

SELECT ST_Length('POLYGON((1 2, 4 2, 4 6, 1 6, 1 2))');
-- Answer: 0.0

SELECT ST_Length('MULTIPOLYGON(((0 2, 3 2, 3 6, 0 6, 0 2)),
                               ((5 0, 7 0, 7 1, 5 1, 5 0)))');
-- Answer: 0.0

SELECT ST_Length('GEOMETRYCOLLECTION(
                    MULTIPOINT((4 4), (1 1), (1 0), (0 3)),
                    LINESTRING(2 1, 1 3, 5 2),
                    POLYGON((1 2, 4 2, 4 6, 1 6, 1 2)))');
-- Answer: 0.0
See also