PostGIS ST_Length() Function
PostGIS ST_Length() returns the 2D length of a linear geometry. For geometry values, the result uses the units of the geometry’s spatial reference system. For geography values, the result is measured in meters by default.
ST_Length() Syntax
This is the syntax of the PostgreSQL length() function:
length(geometric_type) -> double precision
Parameters
geometric_type-
Required. It can be
lseg,path.
Return value
The PostgreSQL length() function returns the total length of the line segment or path specified by the parameter.
length() Examples
The following statement shows how to use PostgreSQL length() function to calculate the total length of path '[(2,0),(0,0)]'.
SELECT length(path '[(2,0),(0,0)]');
length
--------
2The following statement shows how to use PostgreSQL length() function to calculate the total length of path '((2,0),(0,0))'.
SELECT length(path '((2,0),(0,0))');
length
--------
4The following statement shows how to use PostgreSQL length() function to calculate the total length of lseg '(2,0),(0,0)'.
SELECT length(lseg '(2,0),(0,0)');
length
--------
2