Answers:
从PostGIS 2.0(也许以前)开始,您还可以ST_Length
通过将几何图形重铸到地理区域来实现此目的:
ST_Length(geom::geography)
例如,介于50°N,12°E和51°N,13°E之间的距离:
SELECT ST_Length(geom) AS deg,
ST_Length(geom::geography)/1000 AS km_1,
ST_Length_Spheroid(geom, 'SPHEROID["WGS 84",6378137,298.257223563]')/1000 as km_2
FROM ST_GeomFromText('LINESTRING(12 50, 13 51)' , 4326) AS geom
这使
deg | km_1 | km_2
-----------------+------------------+------------------
1.4142135623731 | 131.935962780384 | 131.935962780384
SQL请求的示例:如何计算Postgis中多个表的折线几何长度
SQL请求(以公里为单位的长度(/ 1000-米的删除)):
SELECT
sum(ST_Length_Spheroid(the_geom,'SPHEROID["WGS 84",6378137,298.257223563]'))/1000 AS km_roads
FROM
"D1_r";