Skip to content

Instantly share code, notes, and snippets.

@bravikov
Created April 3, 2020 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bravikov/5fcf398ab2478f9af0753430846b16e2 to your computer and use it in GitHub Desktop.
Save bravikov/5fcf398ab2478f9af0753430846b16e2 to your computer and use it in GitHub Desktop.
Get an azimuth and a distance between two points
from geographiclib.geodesic import Geodesic
'''
Возвращает азимут по направлению от координаты 1 к координате 2
и расстояние между этими координатами.
Результат помещается в словарь с полями:
'distance' (расстояние),
'azimuth' (азимут).
Поля содержат значения типа float.
Возвращает None, если азимут и расстоние недоступны.
Проверить работу функции можно с помощью вызова:
get_azimuth_and_distance(55.751052, 37.623968, 50.45, 30.524166)
который должен вернуть:
{'distance': 755.092, 'azimuth': 221.693}.
'''
def get_azimuth_and_distance(latitude1, longitude1, latitude2, longitude2):
result = Geodesic.WGS84.Inverse(latitude1, longitude1, latitude2, longitude2)
distance_km = result['s12'] / 1000
azimuth = result['azi1']
if azimuth < 0:
azimuth = 360 + azimuth
distance_km = round(distance_km, 3)
azimuth = round(azimuth, 3)
return {'distance': distance_km, 'azimuth': azimuth}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment