s2sphere is a Python implementation of a part of Google's C++ S2 Geometry Library. It provides tools for working with spherical geometry, such as mapping points and regions on a sphere to a 1D index, enabling scalable proximity searches on distributed indexes. The current version is 0.2.5, and it maintains an active release cadence, primarily via updates to its GitHub repository and PyPI package. [1, 2, 3]
pip install s2sphereVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `s2sphere` to find S2 cells covering a geographical region defined by two latitude-longitude points. It then shows how to convert one of these cell IDs back to its center latitude and longitude. [1, 3]
Monitor official `s2sphere` and `google/s2geometry` repositories for announcements regarding API changes. Pin library versions in `requirements.txt` to mitigate unexpected updates.
When iterating with `walk_hilbert_curve`, ensure you explicitly create a *copy* of the `CellId` instance if you need to retain its value outside the current iteration. E.g., `for cell_id_obj in cell.walk_hilbert_curve(level): current_id = s2sphere.CellId(cell_id_obj.id) # Create a new instance`
Always remember the spherical nature of S2 geometry. Utilize `s2sphere`'s dedicated methods for distance calculations, region coverings, and geometric operations that correctly account for Earth's curvature. Convert latitude/longitude pairs to `s2sphere.LatLng` and `s2sphere.Point` for accurate operations.
Before using `CellId` or `Cell` methods, convert the hex-encoded string token into an `s2sphere.CellId` object using `s2sphere.CellId.from_token('your_hex_token_string')`.Ensure that inputs to `s2sphere` functions match the expected type (e.g., lists of `CellId` objects, `LatLonRect` objects). If you have a single `CellId` and a function expects an iterable, wrap it in a list `[my_cell_id]`. Remember that `CellId` objects have an `id` attribute which is an integer, and the `CellId` object itself is what is typically passed around.
No dependency data recorded yet.