【问题标题】:PostGIS mismatch between 2D Distance ("<->" operator; geometry) and ST_Distance (geography) sorting orders2D 距离(“<->”运算符;几何)和 ST_Distance(地理)排序顺序之间的 PostGIS 不匹配
【发布时间】: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


【解决方案1】:

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

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

这与您的结果非常吻合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多