ST_LengthSpheroid — Renvoie la longueur/périmètre 2D ou 3D d'une géométrie lon/lat sur un sphéroïde.
float ST_LengthSpheroid(geometry a_geometry, spheroid a_spheroid);
Calculates the length or perimeter of a geometry on a spheroid. This is useful if the coordinates of the geometry are in longitude/latitude and a length is desired without reprojection. The spheroid is specified by a text value as follows:
SPHEROID[<NAME>,<SEMI-MAJOR AXIS>,<INVERSE FLATTENING>]
Par exemple :
SPHEROID["GRS_1980",6378137,298.257222101]
Disponibilité : 1.2.2
Modifié : 2.2.0 Dans les versions précédentes, cette fonction s'appelait ST_Length_Spheroid et avait l'alias ST_3DLength_Spheroid
Cette fonction prend en charge la 3D et ne supprime pas l'indice z.
Measure a table geometry directly on a spheroid when the coordinates are stored in longitude and latitude.
SELECT ST_LengthSpheroid(
geometry_column,
'SPHEROID["GRS_1980",6378137,298.257222101]'
)
FROM geometry_table;
This example measures a 2D MultiLineString and each component separately on the same spheroid.
WITH sample AS (
SELECT 'MULTILINESTRING((-118.584 38.374,-118.583 38.5),
(-71.05957 42.3589,-71.061 43))'::geometry AS geom,
CAST('SPHEROID["GRS_1980",6378137,298.257222101]' AS spheroid) AS sph_m
)
SELECT ST_LengthSpheroid(geom, sph_m) AS tot_len,
ST_LengthSpheroid(ST_GeometryN(geom, 1), sph_m) AS len_line1,
ST_LengthSpheroid(ST_GeometryN(geom, 2), sph_m) AS len_line2
FROM sample;
tot_len | len_line1 | len_line2 ------------------+------------------+------------------ 85204.52077117894 | 13986.87252824332 | 71217.64824293563
This example uses 3D input; Z contributes to the measured result.
WITH sample AS (
SELECT 'MULTILINESTRING((-118.584 38.374 20,-118.583 38.5 30),
(-71.05957 42.3589 75,-71.061 43 90))'::geometry AS geom,
CAST('SPHEROID["GRS_1980",6378137,298.257222101]' AS spheroid) AS sph_m
)
SELECT ST_LengthSpheroid(geom, sph_m) AS tot_len,
ST_LengthSpheroid(ST_GeometryN(geom, 1), sph_m) AS len_line1,
ST_LengthSpheroid(ST_GeometryN(geom, 2), sph_m) AS len_line2
FROM sample;
tot_len | len_line1 | len_line2 ------------------+-----------------+------------------ 85204.52592562366 | 13986.876103023424 | 71217.64982260024