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