GeographicLib

2.1 · active · verified Sun Apr 05

GeographicLib is a Python implementation of the geodesic routines from the larger C++ GeographicLib library. It provides accurate algorithms for solving direct and inverse geodesic problems, as well as calculating areas on an ellipsoid model of the Earth. The current version is 2.1, and it maintains a regular release cadence with updates tagged in its GitHub repository.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `Geodesic` class to calculate the inverse (distance and azimuth between two points) and direct (finding a point given a starting point, azimuth, and distance) geodesic problems using the WGS84 ellipsoid.

from geographiclib.geodesic import Geodesic

# Define the WGS84 ellipsoid
geod = Geodesic.WGS84

# Solve the inverse geodesic problem (distance and azimuth between two points)
# From Wellington, NZ (-41.32, 174.81) to Salamanca, Spain (40.96, -5.50)
g = geod.Inverse(-41.32, 174.81, 40.96, -5.50)
print(f"The distance is {g['s12']:.3f} meters.")

# Solve the direct geodesic problem (find a point at a given distance and azimuth)
# 20000 km SW of Perth, Australia (-32.06, 115.74)
g = geod.Direct(-32.06, 115.74, 225, 20000e3)
print(f"The position is ({g['lat2']:.8f}, {g['lon2']:.8f}).")

view raw JSON →