11

我需要计算之间的距离

  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

我得到奇怪的结果 - 距离总是小于 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
4

1 回答 1

18

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

OSMway几何数据具有纬度和经度 ( SRID=4326) 的长度单位。因此,ST_Distance的输出单位也会有 lenth 度单位,这并不是真正有用的。

您可以做几件事:

  • 使用ST_Distance_Sphere获得以米为单位的快速/近似距离
  • 使用ST_Distance_Spheroid获得以米为单位的准确距离
  • 将 lat/longgeometry数据类型转换为geography,这会自动使 ST_Distance 和其他函数使用米的线性单位
于 2012-11-05T01:22:48.903 回答