lair.geo.haversine#
- lair.geo.haversine(lat1, lon1, lat2, lon2, R=6371, deg=True)[source]#
Great-circle distance between two points on a sphere (haversine formula).
Formula 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, so a fixed point against many points works.
- Parameters:
lat1 (float or array-like) – First point.
lon1 (float or array-like) – First point.
lat2 (float or array-like) – Second point.
lon2 (float or array-like) – Second point.
R (float, default 6371) – Sphere radius. The result is in the same units (default: mean Earth radius in km, so the result is in km).
deg (bool, default True) – Whether the inputs are in degrees (
False: radians).
- Returns:
float or np.ndarray – Distance in the units of
R.