ST_LENGTH()

All functions > GEOSPATIAL > ST_LENGTH()

Returns the length of a linear geometry or geography.

Signatures

Length

Returns: Length of the input

ST_LENGTH(geo: T) → DOUBLE
sql
ParameterTypeRequiredDescription
geoTYesGeometry or geography value

With:

  • T : Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY | GEOG_POINT | GEOG_LINESTRING | GEOG_POLYGON | GEOG_MULTIPOINT | GEOG_MULTILINESTRING | GEOG_MULTIPOLYGON | GEOG_MULTIANY

Signature notes:

  • On GEOMETRY: returns planar length in SRID coordinate units
  • On GEOGRAPHY: returns the length in meters on a sphere of radius 6 371 008.8 m (the mean Earth radius), with great-circle edges; this differs from the WGS84 ellipsoid by up to about 0.5 %
  • Returns 0.0 for Point, Polygon, MultiPoint, MultiPolygon (not NULL)
  • On GeometryCollection: returns the sum of lengths of linear children
  • Returns NULL if the input is NULL

Availability

StatusBackends
Not availableclickhouse, mysql

Examples

Geometry (planar length)

FeatureQL
RETURN
    -- Length of a 3/4/5 line
    f1 := ST_LENGTH(ST_GEOMFROMTEXT('LINESTRING (0 0, 3 4)'))
;
Result
f1 DECIMAL
5.0

Geography (length in meters)

FeatureQL
RETURN
    -- Length of a point is 0
    f1 := ST_LENGTH(ST_GEOMPOINT(1.0, 2.0))
;
Result
f1 DECIMAL
0.0