Returns the 2D length of a linear geometry.
Syntax
float ST_Length(geometry a2dlinestring);
float ST_Length(geography geog, boolean useSpheroid);Parameters
| Parameter | Description |
|---|---|
a2dlinestring | The 2D linear geometry object. |
geog | The geography object. |
useSpheroid | Specifies whether to use an ellipsoid model. |
Description
For geometry objects:
Returns the 2D Cartesian length if the input is a LineString, MultiLineString, ST_Curve, or ST_MultiCurve.
Returns
0for surface geometries. To get the perimeter of a surface, use ST_Perimeter instead.The unit of the result is determined by the spatial reference system (SRS) of the geometry object.
For geography objects:
Returns the inverse geodesic distance in meters.
Examples
Calculate the length of a LineString geometry
SELECT ST_Length('LINESTRING(0 0,1 1)'::geometry);
st_length
-----------------
1.4142135623731
(1 row)What's next
ST_Perimeter — Calculate the perimeter of a surface geometry or geography object