如何在 Python 中计算由坐标字符串表示的两点之间的距离和方位角
问题:
你在 Python 中有由某些坐标字符串表示的两个点:
input_coords.py
a = "N 48° 06.112' E 11° 44.113'"
b = "N 48° 06.525' E 11° 44.251'"并且你想计算它们之间的方位角和距离
解决方案
这可以使用我们之前两篇文章的组合来完成:
compute_from_strings.py
from geographiclib.geodesic import Geodesic
from geopy.geocoders import ArcGIS
geolocator = ArcGIS()
a = geolocator.geocode("N 48° 06.112' E 11° 44.113'")
b = geolocator.geocode("N 48° 06.525' E 11° 44.251'")
result = Geodesic.WGS84.Inverse(a.latitude, a.longitude, b.latitude, b.longitude)
distance = result["s12"] # 单位 [m](米)
bearing = result["azi1"] # 单位 [°](度)我们示例的结果:
result_summary.py
distance = 784.3069649126435 # m
bearing = 12.613924599757134 # °If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow