earthkit.geo.distance.haversine_distance

earthkit.geo.distance.haversine_distance(p1, p2, figure=IFS_SPHERE)

Compute haversine distance between two (sets of) points on a spheroid.

Parameters:
  • p1 (pair of array-like) – Locations of the first points. The first item specifies the latitudes, the second the longitudes (degrees)

  • p2 (pair of array-like) – Locations of the second points. The first item specifies the latitudes, the second the longitudes (degrees)

  • figure (geo.figure.Figure, optional) – Figure of the spheroid (default: geo.figure.IFS_SPHERE)

Returns:

Distance (m) on the surface of the spheroid defined by figure.

Return type:

number or ndarray

Either p1 or p2 must be a single point.

Examples

Compute the distance between Reading and Bologna.

>>> from earthkit.geo import haversine_distance
>>> p1 = (51.45, -0.97)
>>> p2 = (44.49, 11.34)
>>> haversine_distance(p1, p2)
1196782.5785709629

Compute the distance from Reading to Bologna and Bonn.

>>> from earthkit.geo import haversine_distance
>>> p1 = (51.45, -0.97)
>>> p_lat = [44.49, 50.73]
>>> p_lon = [11.34, 7.90]
>>> haversine_distance(p1, (p_lat, p_lon))
array([1196782.57857096,  624273.19519049])