名稱

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

另請參閱

ST_GeometryN, ST_Length