如何在 Python 中计算两个 lat/lon 点之间的距离和方位角

问题:

假设我们有以下由 Python 中的纬度和经度表示的点:

points.py
a = (48.11617185, 11.743858785932662)
b = (48.116026149999996, 11.743938922310974)

并且我们想计算这些点在 WGS84 或你选择的任何其他大地水准面上的距离方位角

解决方案

我们可以使用 geographiclib 来做到这一点:

compute_distance_bearing.py
from geographiclib.geodesic import Geodesic

result = Geodesic.WGS84.Inverse(*a, *b)
distance = result["s12"] # 单位 [m](米)
bearing = result["azi1"] # 单位 [°](度)

Geodesic.WGS84.Inverse(*a, *b) 只是 Geodesic.WGS84.Inverse(a[0], a[1], b[0], b[1]) 的简写,所以不要对语法感到困惑。

使用我们上面的示例坐标,result

result.json
{'lat1': 48.11617185,
 'lon1': 11.743858785932662,
 'lat2': 48.116026149999996,
 'lon2': 11.743938922310974,
 'a12': 0.00015532346032069415,
 's12': 17.26461706032189,
 'azi1': 159.78110567187977,
 'azi2': 159.7811653333465}

因此,

result_summary.py
distance = 17.26461706032189 # m
bearing = 159.78110567187977 # °

Check out similar posts by category: Geography, Python