clouddrift.sphere.distance

Contents

clouddrift.sphere.distance#

clouddrift.sphere.distance(lon1: float | list | ndarray | DataArray, lat1: float | list | ndarray | DataArray, lon2: float | list | ndarray | DataArray, lat2: float | list | ndarray | DataArray) float | ndarray[source]#

Return elementwise great circle distance in meters between one or more points from arrays of their latitudes and longitudes, using the Haversine formula.

d = 2⋅r⋅asin √[sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)]

where (φ, λ) is (lat, lon) in radians and r is the radius of the sphere in meters.

Parameters#

lon1np.ndarray

Longitudes of the first set of points, in degrees

lat1np.ndarray

Latitudes of the first set of points, in degrees

lon2np.ndarray

Longitudes of the second set of points, in degrees

lat2np.ndarray

Latitudes of the second set of points, in degrees

Returns#

outnp.ndarray

Great circle distance

Examples#

Calculate the distance of one degree longitude on the equator:

>>> distance(0, 0, 0, 1)
111318.84502145034

Calculate the distance of one degree longitude at 45-degrees North latitude:

>>> distance(0, 45, 1, 45)
78713.81064540472

You can also pass array-like inputs to calculate an array of distances:

>>> distance([0, 0], [0, 45], [0, 1], [1, 45])
array([111318.84502145,  78713.8106454 ])