如果你是重新發明輪子一點點OK,你可以在(緯度,經度)對轉換爲笛卡爾單位向量,然後只是比較那些使用點積的產品。由於點積基本上是一個矢量投影到另一個矢量的度量,所以與1最接近的乘積(最大值)將是兩個矢量之間的最佳匹配。
下面的示例計算基於this answer。我將讓您在WGS84橢球提供大地座標(因爲什麼GPS使用)的假設,而橢球以上的高度,是對所有點零:
from math import radians, sin, cos
import numpy as np
# WGS 84 parameters. Any other ellipsoid can be plugged in by changing
# the following lines. All parameters are taken from Wikipedia at
# https://en.wikipedia.org/wiki/Geodetic_datum#Parameters_for_some_geodetic_systems
invFlat = 298.257222101 # Inverse flattening (1/f), unitless
# Derived parameters
e2 = 6694.37999014 # First eccentricity squared. Unitless. Can be computed from 2*f − f**2
# Note that the radius is irrelevant since we are going to
# normalize the result anyway.
def cartesianUnitVector(lat, lon, isdeg=True):
if isdeg:
lat, lon = radians(lat), radians(lon)
vec = np.array([
cos(lat) * cos(lon),
cos(lat) * sin(lon),
(1 - e2) * sin(lat)
])
norm = np.linalg.norm(vec)
return vec/norm
target = (32.815130, -117.151695)
candidates = [
(32.604187, -117.005745),
(37.920948, -108.005043),
(39.70122, -104.876976),
(38.844032, -104.718307)
]
max(candidates, key=lambda x: np.dot(cartesianUnitVector(*x), cartesianUnitVector(*target)))
的大地到ECEF公式可以在Wikipedia找到。這個例子展示瞭如何在迭代的lat-lon對上進行操作。我不完全確定如何適應熊貓,但你的問題是如何做比較,我想我已經提供了一個答案。我確信,一旦你定義了轉換函數和使用它的比較鍵,你就可以毫無困難地將它應用於熊貓。
你看過'geopandas'嗎? –
據我所知,我沒有看到任何方法在geopandas比較geohashes。 – user3447653
最近的經緯度與最短的距離是不是最接近的geohash? –