微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql – ST_Distance的返回值单位

我需要计算之间的距离

>所有建筑物和
>所有医院

在从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,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,planet_osm_point.way hospital_location
from planet_osm_point  
where amenity = 'hospital') hospitals
ORDER BY distance
单位的一般规则是输出长度单位与输入长度单位相同.

OSM方式几何数据具有纬度和经度(SRID=4326)的长度单位.因此,ST_Distance年度的产出单位也将具有十六度学位,这并不真正有用.

你可以做几件事情:

>使用ST_Distance_Sphere快速/近似距离(以米为单位)
>使用ST_Distance_Spheroid以米为单位的精度距离>将纬度/长几何数据类型转换为地理位置,自动使ST_distance和其他函数使用线性单位的米

原文地址:https://www.jb51.cc/postgresql/191776.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐