Planetary-scale answers, unlocked.
A Hands-On Guide for Working with Large-Scale Spatial Data. Learn more.
H3 is an open-source geospatial indexing system that divides the Earth into hexagonal cells and gives each cell a 64-bit ID. Uber built H3 to analyze its marketplace by area, then open sourced it in 2018 under the Apache 2 license. The grid has 16 resolutions, from cells the size of a continent to cells under a square meter. Converting latitude and longitude to an H3 cell turns a location into a number that databases can group, sort, and join, which is why H3 shows up in mobility, insurance, retail, and geospatial analysis.
H3 starts with an icosahedron, a solid with 20 triangular faces. Uber's engineers chose gnomonic projections centered on each face, so the Earth maps onto the icosahedron, and laid a hexagonal grid on the faces. The result is a geodesic discrete global grid: a set of cells that tiles the sphere.
At resolution 0 the grid has 122 cells: 110 hexagons and 12 pentagons. The H3 resolution table shows that every resolution has exactly 12 pentagons, centered on the icosahedron's vertices. Each finer resolution divides every hexagon into seven smaller hexagons, a scheme called aperture 7. Pentagons have six children.
An H3 cell ID is a 64-bit integer. Its bits store a mode, the resolution, one of the 122 base cells, and up to 15 digits, one per resolution, that select a child at each level. The H3 index documentation defines the canonical string form as lowercase hexadecimal, so the integer 617700169994207231 is written 89283082a33ffff. Store the ID as a 64-bit integer or a string. Casting it through a floating-point type rounds away the last digits and points to the wrong cell.
Seven hexagons do not fit exactly inside one larger hexagon, so H3 alternates the grid's orientation between resolutions. The H3 indexing overview explains the result: logical containment in the index is exact, and geographic containment is approximate. A point indexed at resolution 9 and truncated to resolution 7 can fall slightly outside the resolution 7 cell's boundary. Cell boundaries at any single resolution are exact.
Values come from the H3 resolution table, which computes areas on a sphere with the WGS 84 authalic radius. Area varies with position: the largest resolution 9 hexagon is about twice the area of the smallest. Resolution 9 cells average about 0.1 km², a useful size for city-scale analysis.
The H3 comparison with S2 lays out the trade-off. Squares have two kinds of neighbors: four that share an edge and four that share only a corner, at different distances. Hexagons have one kind: all six neighbors share an edge, and their centers sit at the same distance. Moving objects, smoothing, and spreading effects behave more evenly on a hexagonal grid, because grid distance stands in for geographic distance.
The cost is that hexagons do not nest perfectly. S2 squares split exactly into four children, so S2 containment is exact.
The H3 comparison with geohash notes that geohash cells shrink toward the poles, because a degree of longitude spans less distance at high latitudes. String IDs can encode any precision, while H3's fixed 64-bit IDs set a maximum resolution and make integer operations fast.
Pick the resolution from the question and the data:
ST_H3ToParent
H3 is an index, and cell boundaries approximate real ones. For legal or physical boundaries, such as parcels, flood zones, or city limits, use the H3 join to narrow the candidates, then confirm with an exact geometric predicate such as ST_Intersects on the original geometries. The polygon side must be indexed with full coverage (fullCover = true in ST_H3CellIDs), or points near the polygon's edge can fall in cells the polygon never received and drop out before the exact check.
ST_Intersects
fullCover = true
ST_H3CellIDs
WherobotsDB and Apache Sedona include H3 functions in SQL:
ST_H3CellIDs(geom, level, fullCover)
ST_H3ToGeom(cells)
ST_H3KRing(cell, k, exactRing)
ST_H3CellDistance(cell1, cell2)
ST_H3ToParent(cell, resolution)
The header image above comes from this query on Overture places in San Francisco. It indexes each place at resolution 9 and counts places per cell:
SELECT CAST(h3 AS STRING) AS h3_cell, lower(hex(h3)) AS h3_index, COUNT(*) AS places FROM ( SELECT ST_H3CellIDs(geometry, 9, false)[0] AS h3 FROM wherobots_open_data.overture_maps_foundation.places_place WHERE ST_Intersects(geometry, ST_PolygonFromEnvelope(-122.53, 37.70, -122.35, 37.82)) ) GROUP BY h3 ORDER BY places DESC LIMIT 5
Without the limit, the query returns 1,164 cells. A second query explores the busiest cell:
SELECT lower(hex(ST_H3ToParent(617700169994207231, 7))) AS parent_res7, size(ST_H3KRing(617700169994207231, 1, false)) AS ring_1_cells, size(ST_H3KRing(617700169994207231, 2, false)) AS ring_2_cells, ST_H3CellDistance(617700169994207231, 617700169993158655) AS grid_distance, ROUND(ST_AreaSpheroid(ST_H3ToGeom(array(617700169994207231))[0])) AS area_sq_m
The result: its resolution 7 parent is 87283082affffff, one ring holds 7 cells and two rings hold 19, the second-busiest cell is 1 step away, and the hexagon covers 109,461 square meters on the WGS 84 ellipsoid, close to the 105,333 m² average for resolution 9.
A hex count and a count per census tract tell different stories about the same data. Compare this map with the tract-level density map in what is geospatial analysis. Both use the same places from the Havasu catalog.
Index and aggregate billions of points to H3 cells with a Wherobots free trial at cloud.wherobots.com.
H3 is an open-source geospatial indexing system created at Uber that divides the Earth into hexagonal cells at 16 resolutions. Each cell has a 64-bit ID, so any location can be converted to a cell and datasets can be grouped or joined on the ID. Uber open sourced H3 in 2018 under the Apache 2 license.
H3 projects the Earth onto the 20 faces of an icosahedron and lays a hexagonal grid on those faces. Resolution 0 has 122 cells. Each finer resolution splits every hexagon into seven smaller ones, an arrangement called aperture 7. A point is indexed by finding the cell that contains it at the chosen resolution.
The index level, or resolution, sets the cell size. H3 has 16 resolutions, numbered 0 to 15. Resolution 0 hexagons average about 4.36 million square kilometers, resolution 9 hexagons about 0.105 square kilometers, and resolution 15 hexagons under one square meter.
Polyfill returns the set of H3 cells that cover a polygon at a given resolution. In H3 version 4 the function is called polygonToCells. In Wherobots and Apache Sedona, ST_H3CellIDs runs polyfill on polygons, and its fullCover option adds cells so the polygon is completely covered.
Every neighbor of a hexagon shares an edge with it, and all neighbor centers sit at the same distance. Square grids have two kinds of neighbors, edge and corner, at different distances. A single neighbor type makes smoothing, movement, and distance calculations on the grid simpler.
No. Every resolution has exactly 12 pentagons, centered on the vertices of the icosahedron. All other cells are hexagons. A pentagon has five neighbors and six children.
Both are open-source, hierarchical, global grids with 64-bit cell IDs. S2 uses square cells that split exactly into four children. H3 uses hexagonal cells that split approximately into seven children, which gives uniform neighbors at the cost of approximate geographic containment between resolutions.
h3-py is the Python binding for the H3 C library. It exposes the core operations, such as converting a point to a cell, getting a cell’s boundary, and finding neighbors. For datasets too large for one machine, the same operations run in SQL with the ST_H3 functions in Wherobots and Apache Sedona.
What is Geospatial Data? Types, Formats, Examples
Geospatial data describes things tied to a place on Earth. The two main types, vector and raster, plus formats, sources, and examples.
What is Geospatial Analysis? Methods and Examples
Geospatial analysis, or spatial analysis, examines where things are and how location shapes patterns. Methods, examples, GIS vs spatial analysis, and SQL.
What is a Coordinate Reference System? CRS, EPSG
A coordinate reference system (CRS) ties coordinates to places on Earth. Geographic vs projected systems, datums, EPSG codes, WGS 84, UTM, and ST_Transform.
share this article
Awesome that you’d like to share our articles. Where would you like to share it to: