ST_DistanceSphere — 使用球形地球模型返回两个经纬度几何图形之间的最小距离(以米为单位)。
float ST_DistanceSphere(
geometry geomlonlatA, geometry geomlonlatB, float8 radius=6371008)
;
返回两个经纬度点之间的最小距离(以米为单位)。使用球形地球和从 SRID 定义的椭球体派生的半径。比 ST_DistanceSpheroid 快,但精度较低。1.5 之前的 PostGIS 版本仅针对点实现。
可用性:1.5 - 引入了对除点以外的其他几何类型的支持。早期版本仅适用于点。
更改:2.2.0 在早期版本中,这曾经被称为 ST_Distance_Sphere
SELECT round(CAST(ST_DistanceSphere(ST_Centroid(geom), ST_GeomFromText('POINT(-118 38)',4326)) As numeric),2) As dist_meters, round(CAST(ST_Distance(ST_Transform(ST_Centroid(geom),32611), ST_Transform(ST_GeomFromText('POINT(-118 38)', 4326),32611)) As numeric),2) As dist_utm11_meters, round(CAST(ST_Distance(ST_Centroid(geom), ST_GeomFromText('POINT(-118 38)', 4326)) As numeric),5) As dist_degrees, round(CAST(ST_Distance(ST_Transform(geom,32611), ST_Transform(ST_GeomFromText('POINT(-118 38)', 4326),32611)) As numeric),2) As min_dist_line_point_meters FROM (SELECT ST_GeomFromText('LINESTRING(-118.584 38.374,-118.583 38.5)', 4326) As geom) as foo; dist_meters | dist_utm11_meters | dist_degrees | min_dist_line_point_meters -------------+-------------------+--------------+---------------------------- 70424.47 | 70438.00 | 0.72900 | 65871.18