【问题标题】:Unit of return value of ST_DistanceST_Distance 的返回值单位
【发布时间】:2012-10-24 16:41:59
【问题描述】:

我需要计算两者之间的距离

  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

【问题讨论】:

标签: postgresql postgis postgresql-9.2


【解决方案1】:

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

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

你可以做几件事:

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

【讨论】:

    猜你喜欢
    • 2019-06-24
    • 2013-02-16
    • 2018-02-01
    • 2023-03-25
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    相关资源
    最近更新 更多