ST_Distance的返回值单位

DP_*_*DP_ 11 postgresql postgis postgresql-9.2

我需要计算它们之间的距离

  1. 所有的建筑和
  2. 所有医院

在从OSM导入的地图中.

我使用以下查询:

SELECT building_id, hospital_id, ST_Distance(building_centroid, hospital_location)
FROM 
(
select planet_osm_polygon.osm_id building_id, ST_Centroid(planet_osm_polygon.way) building_centroid
from planet_osm_polygon
where building = 'yes'
) buildings,
(
select planet_osm_point.osm_id hospital_id, planet_osm_point.way hospital_location
from planet_osm_point  
where amenity = 'hospital') hospitals
Run Code Online (Sandbox Code Playgroud)

我得到奇怪的结果 - 距离总是小于1.

我怎样才能了解报告这些值的单位?

更新1:示例结果:

上面查询的示例结果

更新2:此查询似乎有效

SELECT building_id, hospital_id, ST_Distance_sphere(building_centroid, hospital_location) distance
FROM 
(
select planet_osm_polygon.osm_id building_id, ST_Centroid(planet_osm_polygon.way)  building_centroid
from planet_osm_polygon
where building = 'yes'
) buildings,
(
select planet_osm_point.osm_id hospital_id, planet_osm_point.way hospital_location
from planet_osm_point  
where amenity = 'hospital') hospitals
ORDER BY distance
Run Code Online (Sandbox Code Playgroud)

Mik*_*e T 16

单位的一般规则是输出长度单位与输入长度单位相同.

OSM way几何数据具有纬度和经度(SRID=4326)的长度单位.因此,ST_Distance的输出单位也将具有最小的度数单位,这些单位并不实用.

你可以做几件事:

  • 使用ST_Distance_Sphere以米为单位的快速/近似距离
  • 使用ST_Distance_Spheroid来计算以米为单位的准确距离
  • 将lat/long geometry数据类型转换为geography自动使ST_Distance和其他函数使用线性单位米