S2 edge neighbours
The four cells across an cell's edges, at the same level, wrapping onto the next cube face where the cell lies on a face edge.
Cell 8834f3dec has four neighbours at level 15.
| Cell | Side | Latitude | Longitude |
|---|---|---|---|
| 8834f3de4 | down | 40.4467945 deg | -79.9850090 deg |
| 8834f3df4 | right | 40.4440289 deg | -79.9822126 deg |
| 8834f3d94 | up | 40.4463067 deg | -79.9794161 deg |
| 8834f3dc4 | left | 40.4490723 deg | -79.9822126 deg |
- Level
- On another face
Provenance
- Computed by
- indexing.s2.neighbors 1.0.0, core 0.1.0
- Model
- The cell's (i, j) stepped by one cell in each direction, taken back through the sphere where it leaves the face, which is how S2 wraps across the cube
- Accuracy
- Matches s2sphere's edge neighbours exactly, in the same order, on 400 cases including cells on face edges.
- Notes
- None
- Cites
- Google, S2 Geometry
Something look off?
How we got thisFormula, worked example, sources, and proof
Model: The cell's (i, j) stepped by one cell in each direction, taken back through the sphere where it leaves the face, which is how S2 wraps across the cube
Accuracy: Matches s2sphere's edge neighbours exactly, in the same order, on 400 cases including cells on face edges.
When to use this: Use this for anything that has to look past one cell: a proximity search that must not miss points just over a boundary, a flood fill, or a smoothing window over cells. The count of neighbours on another cube face is the flag for the awkward cases, where the grid's axes turn.
Limitations: These are the four edge neighbours, not the eight cells touching the corners. Across a face edge the neighbour's own axes are rotated, so stepping further in the same direction is not the same as stepping twice; take neighbours of neighbours rather than adding offsets.
Worked example: The four cells around a level 15 cell. Source: Checked against s2sphere's get_edge_neighbors, in the same order. It is golden test vector v001, and every build checks the tool still gives its answer within its tolerance.
You enter
- S2 cell
- 8834f3dec
You get
- S2 cell
- 8834f3dec
- Level
- 15
- On another face
- 0
Review: Not yet independently reviewed by a GIS professional.
Last verified: 2026-09-22, when a maintainer last confirmed this tool's sources at the issuer. See the sources ledger.
Status: version 1.0.0, core 0.1.0. See this tool in the verification report.
Checked against: 22 golden test vectors (download the test vectors, each with its source and tolerance). See how results are checked and every source.
Sources
- S2 Geometry, Google, S2 Geometry library. Cell ids, the quadratic projection, the Hilbert curve, tokens, and cell hierarchy.
Terms
- S2: S2 Geometry
- A way of indexing the sphere: the Earth is projected onto a cube, each face is traced by a Hilbert curve, and a cell is a position along that curve at a level from 0 to 30. Source: S2 Geometry
S2 — S2 Geometry
A way of indexing the sphere: the Earth is projected onto a cube, each face is traced by a Hilbert curve, and a cell is a position along that curve at a level from 0 to 30.
Source: S2 Geometry