ST_LengthSpheroid — 返回球面体上经纬度几何体的 2D 或 3D 长度/周长。
float ST_LengthSpheroid(geometry a_geometry, spheroid a_spheroid);
计算椭球体上几何体的长度或周长。如果几何体的坐标是经度/纬度,并且希望在不进行重投影的情况下获得长度,这将非常有用。球面体通过文本值指定,如下所示:
SPHEROID[<名称>,<半长轴>,<扁率倒数>]
例如
SPHEROID["GRS_1980",6378137,298.257222101]
可用性:1.2.2
更改:2.2.0 在早期版本中,此函数名为 ST_Length_Spheroid,并具有别名 ST_3DLength_Spheroid
此函数支持 3D,并且不会删除 z 索引。
SELECT ST_LengthSpheroid( geometry_column,
'SPHEROID["GRS_1980",6378137,298.257222101]' )
FROM geometry_table;
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 (SELECT ST_GeomFromText('MULTILINESTRING((-118.584 38.374,-118.583 38.5),
(-71.05957 42.3589 , -71.061 43))') As geom,
CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo;
tot_len | len_line1 | len_line2
------------------+------------------+------------------
85204.5207562955 | 13986.8725229309 | 71217.6482333646
--3D
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 (SELECT ST_GeomFromEWKT('MULTILINESTRING((-118.584 38.374 20,-118.583 38.5 30),
(-71.05957 42.3589 75, -71.061 43 90))') As geom,
CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo;
tot_len | len_line1 | len_line2
------------------+-----------------+------------------
85204.5259107402 | 13986.876097711 | 71217.6498130292