Cut the whole Earth into cells (squares or hexagons) used by Google, Uber and others.
S2 and H3 are two systems that cut the whole Earth into small cells, each with its own ID. Once every place has a cell ID, "what is near here?" becomes a quick lookup of IDs instead of a hard maths problem.
A latitude and longitude pair is exact, but it is hard to search by "nearby". A cell system fixes that: every point is mapped to the cell that contains it, at a chosen size. All points in the same cell share the same ID. To find nearby points, you look up that cell and its neighbour cells.
Cells are nested. A big cell has a set of smaller child cells inside it, so you can zoom in or out by choosing a different level. IDs are plain numbers, so a normal database index can store and search them.
| S2 | H3 | |
|---|---|---|
| Cell shape | Square-like (four-sided) cells on a cube | Hexagons (plus 12 pentagons) |
| Made by | Uber | |
| Children of a cell | 4, and they fit exactly inside | 7, and they fit only roughly |
| Levels | 0 to 30 | 0 to 15 (resolutions) |
| Neighbours | 8 (sides and corners, two distances) | 6 (all one distance) |
| Cell ID | A 64-bit number, with a space-filling curve (Hilbert) so near cells often have near IDs | A 64-bit number |
| Strong at | Exact nesting, covering a region with a few cells of mixed sizes | Even neighbour distance, smooth maps, analytics |
Counts are exact for the formulas shown. Areas are averages: real cells vary in size a little, depending on where they are on the Earth. H3 also has 12 five-sided cells at every resolution, which this flat patch does not show.
| Term | Meaning in easy words |
|---|---|
| Cell | One small area of the Earth's surface, with its own ID |
| Cell ID | A number (64-bit) that names a cell, and also tells its level |
| S2 | Google's system that splits a cube around the Earth into nested square-like cells |
| H3 | Uber's system that covers the Earth with nested hexagon cells |
| Level / resolution | How small the cells are: higher means smaller cells and longer IDs |
| Parent and child | A cell and the smaller cells inside it, one level down |
| Neighbours / ring | The cells touching a cell, and the cells exactly k steps away from it |
| Cell covering | A list of cells that together cover a region such as a city or a circle |
| Hilbert curve | A way of visiting a grid so that cells close in space are often close in the order. S2 uses it |
| Pentagon cells | The 12 five-sided cells that H3 needs to close up the sphere |
| Geohash | A simpler, older text-based grid system. See the Geohash topic |
| Choice | We gain | We lose |
|---|---|---|
| Higher level (smaller cells) | Tighter, more exact results | More cells to search, longer lists |
| Lower level (bigger cells) | Few lookups | More candidates to filter |
| H3 hexagons | Even neighbour distance, smooth analytics | Children only roughly nest |
| S2 squares | Exact nesting, flexible region covering | Two neighbour distances |
| Cells vs a spatial index (R-Tree) | Simple numbers in a normal index, easy to shard | Needs the neighbour search and a final distance check |
| Cells vs Geohash | Better shapes and coverage of the whole sphere | A heavier library to learn |