Example usage

To use karney in a project:

import karney

print(karney.__version__)
1.0.2

Surface distance

Find the surface distance sAB (i.e. great circle distance) between two positions A and B. The heights of A and B are ignored, i.e. if they don’t have zero height, we seek the distance between the points that are at the surface of the Earth, directly above/below A and B. Use Earth radius 6371e3 m. Compare the results with exact calculations for the WGS-84 ellipsoid.

In geodesy this is known as “The second geodetic problem” or “The inverse geodetic problem” for a sphere/ellipsoid.

Solution for a sphere:

import numpy as np
from karney.geodesic import rad, sphere_distance_rad, distance

latlon_a = (88, 0)
latlon_b = (89, -170)
latlons = latlon_a + latlon_b
r_Earth = 6371e3  # m, mean Earth radius
s_AB = sphere_distance_rad(*rad(latlons))[0]*r_Earth
s_AB = distance(*latlons, a=r_Earth, f=0, degrees=True)[0] # or alternatively

"Ex5: Great circle = {:5.2f} km".format(s_AB / 1000)
'Ex5: Great circle = 332.46 km'

Exact solution for the WGS84 ellipsoid:

s_12, azi1, azi2 = distance(*latlons, degrees=True)
"Ellipsoidal distance = {:5.2f} km".format(s_12 / 1000)
'Ellipsoidal distance = 333.95 km'

A and azimuth/distance to B

We have an initial position A, direction of travel given as an azimuth (bearing) relative to north (clockwise), and finally the distance to travel along a great circle given as sAB. Use Earth radius 6371e3 m to find the destination point B.

In geodesy this is known as “The first geodetic problem” or “The direct geodetic problem” for a sphere.

Greatcircle solution

from karney.geodesic import reckon
lat, lon = 80, -90

lat2, lon2, azi_b = reckon(lat, lon, distance=1000, azimuth=200, a=6371e3, f=0, degrees=True)

msg = "Ex8, Destination: lat, lon = {:4.4f} deg, {:4.4f} deg"
msg.format(lat2, lon2)
'Ex8, Destination: lat, lon = 79.9915 deg, -90.0177 deg'
np.allclose(azi_b, -160.0174292682187)
True

Exact solution:

lat_b, lon_b, azi_b = reckon(lat, lon, distance=1000, azimuth=200, degrees=True)
msg.format(lat_b, lon_b)
'Ex8, Destination: lat, lon = 79.9916 deg, -90.0176 deg'
np.allclose(azi_b, -160.01742926820506)
True