简体   繁体   English

ST_Distance的返回值单位

[英]Unit of return value of ST_Distance

I need to calculate the distance between 我需要计算它们之间的距离

  1. all buildings and 所有的建筑和
  2. all hospitals 所有医院

in a map imported from OSM. 在从OSM导入的地图中。

I use following query: 我使用以下查询:

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

I get strange results - the distance is always smaller than 1. 我得到奇怪的结果 - 距离总是小于1。

How can I get the to know the unit, in which these values are reported? 我怎样才能了解报告这些值的单位?

Update 1: Sample result: 更新1:示例结果:

上面查询的示例结果

Update 2: This query seems to work 更新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

The general rule for units is that the output length units are the same as the input length units. 单位的一般规则是输出长度单位与输入长度单位相同。

The OSM way geometry data has length units of degrees of latitude and longitude ( SRID=4326 ). OSM way几何数据具有纬度和经度的长度单位( SRID=4326 )。 Therefore, the output units from ST_Distance will also have lenth units of degrees, which are not really useful. 因此, ST_Distance的输出单位也将具有最小的度数单位,这些单位并不实用。

There are several things you can do: 你可以做几件事:

  • Use ST_Distance_Sphere for fast/approximate distances in metres 使用ST_Distance_Sphere以米为单位的快速/近似距离
  • Use ST_Distance_Spheroid for accurace distances in metres 使用ST_Distance_Spheroid来计算以米为单位的准确距离
  • Convert the lat/long geometry data types to geography , which automagically makes ST_Distance and other functions to use linear units of metres 将纬度/经度geometry数据类型转换为geography ,自动使ST_Distance和其他函数使用线性单位米

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM