ST_Length_Spheroid — Calculates the 2D or 3D length of a Line represented by its latitude/longitude coordinates.
PostgreSQL
geometry ST_Length_Spheroid(bytea
LineString, varchar
Spheroid);
geometry ST_Length_Spheroid(bytea
LineString, integer
SRID);
geometry ST_Length_Spheroid(bytea
LineString);
H2
geometry ST_Length_Spheroid(bytea
LineString, varchar
Spheroid);
geometry
ST_Length_SpheroidEx(bytea
LineString, integer
SRID);
geometry ST_Length_Spheroid(bytea
LineString);
Calculates the 2D or 3D length of a Line represented by its latitude/longitude coordinates. Distance is calculated using a particular spheroid. This spheroid can be given by the SRID or by the text, if it's not given this function searches at the geometry SRID.
![]() | |
This function supports GeometryCollections. |
| 2D | 3D | M |
|---|---|---|
![]() | ![]() | ![]() |
| OGC SFS for SQL. 1.1 (1999) | OGC SFS for SQL. 1.1.0 (2005) | OGC SFS for SQL. 1.2.0 (2006) | SQL-MM Part 3 |
|---|---|---|---|
| - | - | - | - |
--PostgreSQL
SELECT ST_Length_Spheroid(ga) as length_WGS84,
ST_Length_Spheroid( ga,'SPHEROID["GRS_1980",6378137,298.257222101]') as length_GRS80,
ST_Length_Spheroid(ga,25830) as length2_GRS80
from (SELECT ST_GeomFromText('LINESTRING(-3.52 41.0,2.33 48.86)',4326) as ga) as foo;
--H2
SELECT ST_Length_Spheroid(ga) as length_WGS84,
ST_Length_Spheroid( ga,'SPHEROID["GRS_1980",6378137,298.257222101]') as length_GRS80,
ST_Length_SpheroidEx(ga,25830) as length2_GRS80
from (SELECT ST_GeomFromText('LINESTRING(-3.52 41.0,2.33 48.86)',4326) as ga) as foo;
--Result
length_wgs84 | length_grs80 | length2_grs80
------------------+------------------+------------------
987329.984556481 | 987329.984551754 | 987329.984551754
SELECT ST_Length_Spheroid(ga) as length, ST_Length2D_Spheroid(ga) as length2D, ST_Length3D_Spheroid(ga) as length3D
from (SELECT ST_GeomFromText('LINESTRING(-3.52 41.0 50,-3.33 41.86 400)',4326) as ga) as foo;
--Result
length | length2d | length3d
------------------+------------------+------------------
96825.3888661294 | 96824.7562820438 | 96825.3888661294