PyGeodesy
PyGeodesy is a pure Python implementation of geodesy tools for various ellipsoidal and spherical earth models. It offers precision exact, elliptic, trigonometric, vector-based, iterative, and approximate methods for geodetic (lat-/longitude), geocentric (ECEF cartesian), local (LTP), and certain triaxial ellipsoidal coordinates. The library provides functionalities for computing distance, area, bearing, intersections, resections, and conversions across various coordinate systems and earth models. The current version is 26.3.26, and it is actively maintained with frequent updates.
Warnings
- gotcha Some powerful functionalities, like those in `ellipsoidalKarney` and `css` modules, critically depend on the `geographiclib` library. While `pygeodesy` itself is pure Python, `geographiclib` is a Python wrapper around a C++ library. Users expecting a fully pure-Python solution for all features might encounter `ImportError` if `geographiclib` is not installed for these specific use cases.
- gotcha PyGeodesy extensively uses lazy importing, organizing classes like `LatLon` and `Cartesian` within specific model submodules (e.g., `ellipsoidalVincenty`, `sphericalTrigonometry`). Attempting to import these classes directly from the top-level `pygeodesy` package (e.g., `from pygeodesy import LatLon`) will typically fail or lead to unexpected behavior.
- gotcha Certain advanced features, such as some `azimuthal` projections or calculations in `rhumb.solve`, can leverage external Karney's C++ utilities (`GeodSolve`, `RhumbSolve`). While optional, configuring these executables via environment variables (`PYGEODESY_GEODSOLVE`, `PYGEODESY_RHUMBSOLVE`) can provide improved performance or access to specific capabilities not available in the pure Python implementation.
- gotcha PyGeodesy defines a comprehensive set of specific exception types within its `pygeodesy.errors` module (e.g., `GeodesicError`, `RangeError`, `IntersectionError`). Catching a generic `Exception` may obscure the root cause of issues, such as convergence failures in geodesic calculations, out-of-range coordinate values, or unresolved geometric intersections.
Install
-
pip install pygeodesy
Imports
- LatLon
from pygeodesy import LatLon
from pygeodesy.ellipsoidalVincenty import LatLon
- GeoidKarney
from pygeodesy import GeoidKarney
Quickstart
from pygeodesy.ellipsoidalVincenty import LatLon
# Define two geographic points (latitude, longitude)
point1 = LatLon(41.49008, -71.312796) # Newport, RI
point2 = LatLon(41.499498, -81.695391) # Cleveland, OH
# Calculate the geodesic distance between the two points
distance = point1.distanceTo(point2)
print(f"Distance between Newport, RI and Cleveland, OH: {distance:,.2f} meters")