Skip to content

s2

PL/Python functions for converting latitude/longitude to S2 cell IDs and tokens and navigating the S2 cell hierarchy

s2-postgis · PL/Python functions for converting latitude/longitude to S2 cell IDs and tokens and navigating the S2 cell hierarchy

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100145s2s2-postgis0.0.2GISMITPython
Relationships
Requiresplpython3u

Usage

Sources:

s2 version 0.0.2 is a PL/Python wrapper around the Python s2sphere package. It converts latitude/longitude values to signed bigint S2 cell identifiers or text tokens, converts them back, and exposes validity, level, parent, child, neighbor, containment, and intersection helpers.

Example

Install a PostgreSQL-matched plpython3u package and make s2sphere importable by the server’s Python runtime, then run:

CREATE LANGUAGE plpython3u;
CREATE EXTENSION s2;
SELECT s2_cellid_from_latlng(10.1234, -72.1234);
SELECT s2_token_from_latlng(10.1234, -72.1234);

Despite being cataloged as pure SQL, every functional entry point executes untrusted PL/Python and imports a host Python dependency. Only a superuser should install or control plpython3u; pin and audit the exact Python environment. The 2018 repository has no current PostgreSQL, Python, or s2sphere compatibility matrix. S2 cells are hierarchical approximations, so use exact geometry predicates when correctness depends on a true spatial boundary.

Table reader