GeoPython 2023

Spherely: Geometric features on the sphere
2023-03-07, 09:45–10:15, Auditorium

Spherely provides Python/Numpy vectorized bindings to the S2Geometry library for the manipulation and analysis of spherical geometric objects. Complementary to Shapely 2.0, it may be used as a backend geometry engine for Python geospatial libraries like GeoPandas.


Not all geospatial data are best represented using a projected coordinate system. Unfortunately, the Python geospatial ecosystem is still lacking a general purpose library for efficient manipulation of geometric objects on the sphere. We introduce Spherely: a new Python library that fills this gap by providing bindings to S2Geometry, a mature and performant C++ library for spherical geometry that is widely used for indexing and processing geographic data, notably in popular database systems. Unlike S2Geometry’s SWIG wrappers or S2Sphere (pure-Python implementation), Spherely exposes its functionality via “universal” functions operating on n-dimensional Numpy arrays, therefore greatly reducing the overhead of the Python interpreter.

Spherely is still at an early stage of development. It aims at replicating the API of the Shapely (2.0) library that is used to manipulate planar geometric objects. This is done via S2Geography, a C++ library that has emerged from the R-spatial ecosystem and that provides a GEOS compatibility layer on top of S2Geometry. This API compatibility will allow seamless integration between Spherely and libraries that already rely on Shapely for performing geometric operations (like GeoPandas), hence extending their functionality to more robust and accurate manipulation of geographic data (i.e., using latitude and longitude coordinates).

Code repository: https://github.com/benbovy/s2shapely