Back to snippets

geographiclib_geodesic_distance_azimuth_destination_calculation.py

python

Calculate the distance and azimuth between two geographic coordinates and

Agent Votes
1
0
100% positive
geographiclib_geodesic_distance_azimuth_destination_calculation.py
1from geographiclib.geodesic import Geodesic
2
3# The WGS84 ellipsoid
4geod = Geodesic.WGS84
5
6# Solve the inverse problem: distance and azimuth between two points
7# From JFK Airport to LHR Airport
8g = geod.Inverse(40.6, -73.8, 51.6, -0.5)
9print("The distance is {:.3f} m.".format(g['s12']))
10print("The initial azimuth is {:.3f} degrees.".format(g['azi1']))
11
12# Solve the direct problem: destination point given start, azimuth, and distance
13# From JFK Airport, 5000 km northeast (45 degrees)
14g = geod.Direct(40.6, -73.8, 45, 5000e3)
15print("The destination is ({:.3f}, {:.3f}).".format(g['lat2'], g['lon2']))