简体   繁体   English

2D距离(“ <->”运算符;几何)和ST_Distance(地理)排序顺序之间的PostGIS不匹配

[英]PostGIS mismatch between 2D Distance (“<->” operator; geometry) and ST_Distance (geography) sorting orders

Using PostgreSQL 9.5.2, PostGIS 2.2, given the following geo coordinates: 给定以下地理坐标,使用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

Sorting by "geographical" distance ( ST_Distance method ): 按“地理”距离排序( ST_Distance方法 ):

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;

Results in: 结果是:

B,2311.075069284
C,2405.58508757
D,2456.504535795
A,4266.971129052

Whereas sorting by "geometrical" 2D distance ( <-> 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;

Results in: 结果是:

A,0.03862894955858695
B,0.041493463474867306
C,0.042847871457636175
D,0.04418579056948194

... And I would expect the order to be exactly the same. ...而且我希望顺序是完全一样的。

What am I missing? 我想念什么?

You are making the calculations at 60 degrees of latitude. 您正在60度纬度下进行计算。 Here a degree of latitude is much larger than a degree of longitude. 在这里,纬度比经度大得多。 Specifically, at 60 degrees of latitude a degree of latitude is 111.412km, while a degree of longitude is 55.800km. 具体而言,在60度纬度下,纬度为111.412公里,而经度为55.800公里。 This means that the separation in longitude value is much more important than the separation in latitude. 这意味着经度值的分隔比纬度的分隔重要得多。

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

Which nicely corresponds to your result. 恰好与您的结果相对应。

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

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