spherical-geometry

raw JSON →
1.4.0 verified Fri May 01 auth: no python

Python tools for spherical geometry, providing vectorized operations on the sphere using NumPy. Current version 1.4.0, released approximately monthly.

pip install spherical-geometry
error AttributeError: module 'spherical_geometry' has no attribute 'Arc'
cause Using an older version (<1.4.0) where Arc was not exported at package level, or importing incorrectly.
fix
Upgrade to version 1.4.0+ (pip install --upgrade spherical-geometry) and use from spherical_geometry import Arc.
error ValueError: All points must be in radians
cause Passing coordinates in degrees instead of radians.
fix
Convert lon, lat to radians using math.radians() or numpy.radians() before passing to spherical_geometry functions.
breaking In version 1.4.0, the import paths for Arc and GreatCircle changed. Previously they were in submodules; now they are exported at the top-level package. Code using old imports will fail.
fix Use `from spherical_geometry import Arc, GreatCircle` instead of `from spherical_geometry.polygon import Arc` or `from spherical_geometry.great_circle import GreatCircle`.
gotcha All angular coordinates (longitude, latitude) must be in radians, not degrees. The library does not perform conversion, and passing degrees will give incorrect results.
fix Convert degrees to radians using `math.radians()` or `numpy.radians()` before passing to functions.
deprecated The `spherical_geometry.polygon` module is deprecated as of 1.4.0. Its contents have been moved to the top-level package.
fix Use top-level imports as shown in the quickstart.

Basic usage of Arc and GreatCircle for spherical geometry calculations.

from spherical_geometry import Arc, GreatCircle

# Define two points on the sphere (longitude, latitude in radians)
point_a = (0.0, 0.0)
point_b = (1.0, 0.5)

# Create a great circle arc
arc = Arc(point_a, point_b)
print(f"Arc length: {arc.length()}")

# Compute intersection of two great circles
gc1 = GreatCircle(point_a, point_b)
gc2 = GreatCircle((0.5, 0.2), (1.2, 0.8))
intersections = gc1.intersections(gc2)
print(f"Intersection points: {intersections}")