【发布时间】:2016-04-19 11:30:25
【问题描述】:
使用 PostgreSQL 9.5.2,PostGIS 2.2,给定以下地理坐标:
'SRID=4326;POINT(24.8713597 60.1600568)' -- Origin
'SRID=4326;POINT(24.87717970 60.19824480)' -- Destination A
'SRID=4326;POINT(24.91281220 60.15821350)' -- Destination B
'SRID=4326;POINT(24.91404950 60.16373390)' -- Destination C
'SRID=4326;POINT(24.91552820 60.16129280)' -- Destination D
按“地理”距离排序 (ST_Distance method):
select name, st_distance('SRID=4326;POINT(24.8713597 60.1600568)'::geography, geo)
from (select 'SRID=4326;POINT(24.87717970 60.19824480)'::geography as geo, 'A' as name
union select 'SRID=4326;POINT(24.91281220 60.15821350)'::geography as geo, 'B' as name
union select 'SRID=4326;POINT(24.91404950 60.16373390)'::geography as geo, 'C' as name
union select 'SRID=4326;POINT(24.91552820 60.16129280)'::geography as geo, 'D' as name) tmp
order by 2;
结果:
B,2311.075069284
C,2405.58508757
D,2456.504535795
A,4266.971129052
而按“几何”二维距离排序 (<-> Operator):
select name, 'SRID=4326;POINT(24.8713597 60.1600568)'::geometry <-> geom
from (select 'SRID=4326;POINT(24.87717970 60.19824480)'::geometry as geom, 'A' as name
union select 'SRID=4326;POINT(24.91281220 60.15821350)'::geometry as geom, 'B' as name
union select 'SRID=4326;POINT(24.91404950 60.16373390)'::geometry as geom, 'C' as name
union select 'SRID=4326;POINT(24.91552820 60.16129280)'::geometry as geom, 'D' as name) tmp
order by 2;
结果:
A,0.03862894955858695
B,0.041493463474867306
C,0.042847871457636175
D,0.04418579056948194
...而且我希望顺序完全相同。
我错过了什么?
【问题讨论】:
-
这是意料之中的,因为地球不是平坦的,并且您正在将笛卡尔距离与旋转椭球体上的测地线长度进行比较。
标签: postgresql gis postgis