簡體   English   中英

2D距離(“ <->”運算符;幾何)和ST_Distance(地理)排序順序之間的PostGIS不匹配

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

給定以下地理坐標,使用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方法 ):

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

而按“幾何”二維距離( <->運算符 )排序:

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

...而且我希望順序是完全一樣的。

我想念什么?

您正在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

恰好與您的結果相對應。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM