API reference#
earthcarekit.geo.distance
Algorithms to calculate geospatial distances.
Notes#
This module depends on other internal modules:
geodesic
#
geodesic(
a: ArrayLike,
b: ArrayLike,
units: str = "km",
tolerance: float = 1e-12,
max_iterations: int = 10,
) -> float64 | NDArray[float64]
Calculates geodesic distances on the WGS 84 ellipsoid using Vincenty's inverse method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ArrayLike
|
Coordinates [lat, lon] or (N, 2) array in decimal degrees. |
required |
b
|
ArrayLike
|
Second coordinates, same format/shape as |
required |
units
|
str
|
Output units ("km" or "m"); defaults to "km". |
'km'
|
tolerance
|
float
|
Convergence threshold in radians; defaults to 1e-12. |
1e-12
|
max_iterations
|
int
|
Maximum iterations before failure; defaults to 10. |
10
|
Returns:
| Type | Description |
|---|---|
float64 | NDArray[float64]
|
Geodesic distance(s) in the specified units. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input shapes are incompatible, units are invalid, or convergence fails. |
Notes
Uses WGS 84 parameters (a=6378137.0 m, f=1/298.257223563). May fail for nearly antipodal points.
Examples:
>>> import earthcarekit as eck
>>> eck.geodesic([51.352757, 12.43392], [38.559, 68.856])
4548.675334434374
References
- Vincenty, T. (1975). Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations. Survey Review, 23(176), 88-93. https://doi.org/10.1179/sre.1975.23.176.88
Source code in earthcarekit/geo/distance/_vincenty.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
haversine
#
haversine(
a: ArrayLike,
b: ArrayLike,
units: Literal["m", "km"] = "km",
radius: float = MEAN_EARTH_RADIUS_METERS,
)
Calculates great-circle distances between latitude/longitude pairs using the haversine formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ArrayLike
|
Coordinates as (..., 2) array (lat, lon) in degrees. |
required |
b
|
ArrayLike
|
Corresponding coordinates as (..., 2) array (lat, lon) in degrees. |
required |
units
|
Literal['m', 'km']
|
Output unit ("m" or "km"); defaults to "km". |
'km'
|
radius
|
float
|
Sphere radius in meters; defaults to mean earth radius (~6371008.77 m). |
MEAN_EARTH_RADIUS_METERS
|
Returns:
| Type | Description |
|---|---|
|
Great-circle distances in the specified units; shape matches input excluding last dimension. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If shapes of |
Examples:
>>> import earthcarekit as eck
>>> eck.haversine([51.352757, 12.43392], [38.559, 68.856])
4537.564747442274
Source code in earthcarekit/geo/distance/_haversine.py
vincenty
#
vincenty(
a: ArrayLike,
b: ArrayLike,
units: str = "km",
tolerance: float = 1e-12,
max_iterations: int = 10,
) -> float64 | NDArray[float64]
Calculates geodesic distances on the WGS 84 ellipsoid using Vincenty's inverse method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ArrayLike
|
Coordinates [lat, lon] or (N, 2) array in decimal degrees. |
required |
b
|
ArrayLike
|
Second coordinates, same format/shape as |
required |
units
|
str
|
Output units ("km" or "m"); defaults to "km". |
'km'
|
tolerance
|
float
|
Convergence threshold in radians; defaults to 1e-12. |
1e-12
|
max_iterations
|
int
|
Maximum iterations before failure; defaults to 10. |
10
|
Returns:
| Type | Description |
|---|---|
float64 | NDArray[float64]
|
Geodesic distance(s) in the specified units. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input shapes are incompatible, units are invalid, or convergence fails. |
Notes
Uses WGS 84 parameters (a=6378137.0 m, f=1/298.257223563). May fail for nearly antipodal points.
Examples:
>>> import earthcarekit as eck
>>> eck.geodesic([51.352757, 12.43392], [38.559, 68.856])
4548.675334434374
References
- Vincenty, T. (1975). Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations. Survey Review, 23(176), 88-93. https://doi.org/10.1179/sre.1975.23.176.88
Source code in earthcarekit/geo/distance/_vincenty.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |