This topic describes the ST_Length function. This function calculates the length of a LineString object or MultiLineString object within the 2D space of the object.

Syntax

float  ST_Length(geometry  a2dlinestring);
float  ST_Length(geography  geog , boolean  useSpheroid);

Parameters

Parameter Description
a2dlinestring The 2D linear geometry object that you want to specify.
geog The geography object that you want to specify.
useSpheroid Specifies whether to use an ellipsoid model.

Description

  • If you specify a geometry object, the following rules apply:
    • If the geometry object is a LineString, MultiLineString, ST_Curve, or ST_MultiCurve, this function returns a 2D Cartesian length.
    • If the geometry object is a surface, this function returns 0. To obtain the length of a surface within the 2D space of the surface, use the ST_Perimeter function.
    • The length that is returned is measured in the unit that is specified by the spatial reference system of the geometry object.
  • If you specify a geography object, this function returns an inverse geodesic distance, which is measured in meters.

Examples

Calculate the length of a geometry object within the 2D space of the object by using the default parameter settings.
SELECT ST_Length('LINESTRING(0 0,1 1)'::geometry);
    st_length
-----------------
 1.4142135623731
(1 row)