PostGIS在“2D距离”(“< - >”操作员;几何图形)和ST_Distance(地理位置)排序顺序之间不匹配

时间:2016-04-19 11:30:26

标签: postgresql gis postgis

使用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

然而按“几何”2D距离(<-> 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

......我希望订单完全一样。

我错过了什么?

1 个答案:

答案 0 :(得分:1)

您正在以60度纬度进行计算。这里的纬度比经度大得多。具体而言,在纬度60度,纬度为111.412km,经度为55.800km。这意味着经度值的分离比纬度的分离更重要。

A 24.87717970 - 24.8713597 = 0.006...
B 24.91281220 - ... = 0.041...
C 24.91404950 - ... = 0.043...
D 24.91552820 - ... = 0.044

与您的结果非常吻合。