lair.geo.bearing#

lair.geo.bearing(lat1, lon1, lat2, lon2, deg=True, final=False)[source]#

Great-circle bearing from point 1 to point 2 on a sphere.

Formulas from https://www.movable-type.co.uk/scripts/latlong.html. Vectorized: any argument can be an array (or pandas Series), broadcast together with numpy rules.

Parameters:
  • lat1 (float or array-like) – Start point.

  • lon1 (float or array-like) – Start point.

  • lat2 (float or array-like) – End point.

  • lon2 (float or array-like) – End point.

  • deg (bool, default True) – Whether the inputs are in degrees (False: radians). The output is always in degrees.

  • final (bool, default False) – Return the final bearing (the course on arrival at point 2) instead of the initial bearing (the course on leaving point 1). The two differ along a great circle unless the path follows a meridian or the equator.

Returns:

float or np.ndarray – Bearing in degrees clockwise from true north, in [0, 360). Coincident points return 0.

Examples

>>> round(float(bearing(40, -111, 41, -111)), 6)  # due north
0.0
>>> round(float(bearing(35, 45, 35, 135)), 2)  # Baghdad -> Osaka
60.16
>>> round(float(bearing(35, 45, 35, 135, final=True)), 2)
119.84