What S2 is
S2 is a discrete global grid system originating at Google. It projects a cube onto the sphere — each of the cube's 6 faces maps to a curved quadrilateral region of the sphere — and subdivides each face hierarchically into smaller quadrilaterals, producing a grid of quadrilateral cells at 31 levels, numbered 0 (a whole cube face) through 30 (finest). Like H3 and Geohash, S2 is one of the non-canonical cell systems this knowledge base's generic model must support without assuming H3-specific properties; see cell-system-comparison for the full cross-system matrix.
Hierarchy: exact quad subdivision
S2's defining structural property, and the sharpest contrast with H3, is
that its hierarchy is an exact quad tree: every cell at level N is
subdivided into exactly 4 children at level N+1, and the union of those 4
children's true boundaries exactly reproduces the parent's true boundary,
with no gap and no overlap. This is a stronger and qualitatively different
guarantee than H3's aperture-7 hierarchy, where a parent's 7 (approximate)
children are a logical, index-arithmetic relationship that does not
exactly geometrically tile the parent. Practically: coarsening or
refining an S2 cell set by walking the cell-ID hierarchy reproduces the
same covered region exactly, at any level, with no boundary drift —
whereas the same operation on an H3 cell set can introduce small boundary
discrepancies that must be measured (coverage_ratio, jaccard), not
assumed away.
Levels and cell size
S2 has 31 levels (0-30). A level-0 cell is one sixth of the sphere's surface (a full cube face); each level down quarters the area of the level above, so cell area shrinks by a factor of 4 per level, versus H3's factor of roughly 7 per resolution — the two numbering systems are independent and do not correspond level-for-level. S2 is explicitly not equal-area: the cube-to-sphere projection distorts area non-uniformly across a face, so a cell near a face's center is smaller than a same-level cell near a face edge or corner — comparable in kind, though not magnitude or pattern, to H3's projection-driven area variance. Neither S2 nor H3 is equal-area.
Quadrilateral cells and neighbours
S2 cells are quadrilaterals everywhere — there is no pentagon-equivalent structural exception the way H3 has 12 unavoidable pentagons per resolution. A typical S2 cell has 4 edge-adjacent neighbours; cells at a cube face's corner or along a face boundary can have additional neighbour relationships to account for the discrete jump between the two adjoining faces' coordinate systems, but this is a face-boundary bookkeeping detail, not a shape exception comparable to an H3 pentagon.
Index representation: Hilbert curve cell ID
Each S2 cell is addressed by a 64-bit integer whose bits encode the cube face (3 bits, for 6 faces) followed by the cell's position along a Hilbert space-filling curve traversal of that face at the target level. The Hilbert-curve ordering is deliberate: cells that are numerically close in S2 cell-ID order are also spatially close on the sphere, a useful locality property for range-based spatial indexing (a database B-tree or key-range scan over S2 cell IDs tends to group nearby cells) — distinct from H3's index, which encodes an explicit resolution/base-cell/digit-path structure rather than a curve position.
Core operations
- Point indexing
- A lat/lng point maps to its containing S2 cell ID at a given level via the cube-face projection followed by Hilbert-curve position lookup — the S2 equivalent of H3's `latLngToCell`.
- Polygon covering
- `S2RegionCoverer` produces a cell covering for an arbitrary region, parameterized by min/max level and a max-cells budget, analogous in purpose to H3's `polygonToCells` but tuned by a cell-count budget rather than a single containment mode.
- Boundary extraction
- Each S2 cell's exact quadrilateral vertex boundary can be recovered from its cell ID and level, the S2 equivalent of `cellToBoundary`.
- Centroid extraction
- A cell's center point is derivable from its cell ID, analogous to `cellToLatLng`.
- Compaction
- Because a parent cell ID's children are a fixed, deterministic range of cell IDs (all descendants of a level-N cell fall within a contiguous ID range), S2 supports compacting a set of same-level cells into coarser parent IDs where a full set of 4 (or a full descendant range) is present — implemented via cell-ID range arithmetic rather than a bespoke compaction algorithm.
Relevance: exact containment for spatial indexing and joins
S2's exact quad containment is specifically why it is a common choice for spatial indexing and geometric joins in database and search systems: a range query over Hilbert-ordered S2 cell IDs reliably returns all cells within a region with no approximation-driven boundary leakage between parent and child levels, and "does cell A contain cell B" is answerable by comparing cell-ID ranges alone, without a geometric boundary computation. H3 cannot offer that same guarantee, because its hierarchy is logical rather than exact — which is precisely why this knowledge base recommends H3 for advertising execution (where hexagon-shaped catchment approximation and aperture-7 resolution steps are the relevant properties) while flagging S2 as the stronger choice specifically where exact containment is load-bearing, such as backing a spatial join or a range-indexed store.
What must not be assumed
Do not assume S2 shares H3's resolution numbering, aperture-7 area ratio, hexagon shape, 6-neighbour structure, or pentagon exceptions — none of these apply. Do not assume S2 is equal-area — it is not, though its area variance arises from a cube projection rather than an icosahedron projection. Do assume S2's parent-child containment is exact, which is the one hierarchy property that is stronger, not weaker, than H3's.
References
- S2 Geometry — Google, s2geometry.io (last verified 2026-07-22)
Assumptions and limitations
This page describes S2's generic capability model as registered in
data/cell-systems.yaml. Exact level count, cell-ID bit layout, and
S2RegionCoverer parameter defaults should be verified against the
current S2 library documentation before being relied on for a production
calculation.
