# H3 Hex Index

Key: `geography.index.h3`

Uber H3 hierarchical hexagonal spatial index. A 15-character lowercase hexadecimal string encoding resolution (0-15) and cell position.

Page: <https://meridian.online/docs/projects/finetype/types/geography/index/h3>

Samples: `8928308280fffff`, `891f1d4c6c7ffff`, `8a2a1072b59ffff`, `872830828ffffff`, `8e28308280f0e4f`

## Background

### Origin

H3 is a geospatial indexing system that partitions the world into hexagonal cells.[[1]](https://h3geo.org/docs/) H3 was developed to address the challenges of Uber's data science needs.[[1]](https://h3geo.org/docs/) Uber's post describes H3 as its grid system for efficiently optimising ride pricing and dispatch.[[2]](https://www.uber.com/en-US/blog/h3/) Uber's post explains the choice of hexagons by noting that hexagons have only one distance between a hexagon centrepoint and its neighbours'.[[2]](https://www.uber.com/en-US/blog/h3/) Uber's post also says that hexagons minimise the quantisation error introduced when users move through a city.[[2]](https://www.uber.com/en-US/blog/h3/) H3 is open source under the Apache 2 licence.[[1]](https://h3geo.org/docs/) The H3 library is written in C, and bindings are available for a number of languages.[[2]](https://www.uber.com/en-US/blog/h3/)

H3 supports sixteen resolutions.[[2]](https://www.uber.com/en-US/blog/h3/) Each finer H3 resolution has cells with one seventh the area of the coarser resolution.[[2]](https://www.uber.com/en-US/blog/h3/) Uber's post notes that the finer cells are only approximately contained within a parent cell.[[2]](https://www.uber.com/en-US/blog/h3/) An H3Index is the 64-bit integer representation of an H3 index.[[3]](https://h3geo.org/docs/core-library/h3Indexing) The H3 documentation defines several index modes, of which mode 1 is an H3 Cell (hexagon or pentagon) index.[[3]](https://h3geo.org/docs/core-library/h3Indexing) An H3 cell index packs its components into a 64-bit integer in order, highest bit first.[[4]](https://h3geo.org/docs/library/index/cell) An H3 cell index uses 4 bits to indicate the cell resolution, from 0 to 15.[[4]](https://h3geo.org/docs/library/index/cell) An H3 cell index uses 7 bits to indicate the base cell, from 0 to 121.[[4]](https://h3geo.org/docs/library/index/cell) An H3 cell index uses 3 bits for each subsequent digit, from resolution 1 up to the resolution of the cell, each digit holding a value from 0 to 6.[[4]](https://h3geo.org/docs/library/index/cell) In an H3 cell index, the three bits for each unused digit are set to 7.[[4]](https://h3geo.org/docs/library/index/cell) The canonical string representation of an H3Index is the hexadecimal representation of the integer, using lowercase letters.[[3]](https://h3geo.org/docs/core-library/h3Indexing)

### Use

DuckDB's h3 community extension is installed with INSTALL h3 FROM community and loaded with LOAD h3.[[5]](https://duckdb.org/community_extensions/extensions/h3.html) DuckDB's h3 extension provides h3\_string\_to\_h3, which converts a VARCHAR cell ID to UBIGINT.[[5]](https://duckdb.org/community_extensions/extensions/h3.html) DuckDB's h3 extension provides h3\_is\_valid\_cell, which is true if its argument is a valid cell ID.[[5]](https://duckdb.org/community_extensions/extensions/h3.html) Snowflake's H3\_LATLNG\_TO\_CELL\_STRING function returns a VARCHAR value holding the hexadecimal H3 cell ID for a given location and resolution.[[6]](https://docs.snowflake.com/en/sql-reference/functions/h3_latlng_to_cell_string) Databricks provides h3\_stringtoh3, which converts a hexadecimal string representing an H3 cell ID to its BIGINT form.[[7]](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-h3-geospatial-functions) Databricks recommends the big integer representation of H3 cell IDs for the best performance.[[7]](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-h3-geospatial-functions)

Read the resolution of the cells before you aggregate or join, since a column that mixes resolutions is easy to miss by eye. (Meridian's view)

### Where you'll meet it

Kontur's global population dataset on the Humanitarian Data Exchange publishes vector H3 hexagons with population counts at 400m resolution.[[8]](https://data.humdata.org/api/3/action/package_show?id=kontur-population-dataset) The Kontur Population codebook lists an h3 field holding the H3 index of each hexagon.[[8]](https://data.humdata.org/api/3/action/package_show?id=kontur-population-dataset)

## Sources

1. [Introduction \| H3](https://h3geo.org/docs/) — documentation
2. [Uber's Hexagonal Hierarchical Spatial Index (H3)](https://www.uber.com/en-US/blog/h3/) — documentation
3. [H3 Index \| H3](https://h3geo.org/docs/core-library/h3Indexing) — documentation
4. [Cell mode \| H3](https://h3geo.org/docs/library/index/cell) — documentation
5. [h3 – DuckDB Community Extensions](https://duckdb.org/community_extensions/extensions/h3.html) — documentation
6. [H3\_LATLNG\_TO\_CELL\_STRING \| Snowflake Documentation](https://docs.snowflake.com/en/sql-reference/functions/h3_latlng_to_cell_string) — documentation
7. [H3 geospatial functions \| Databricks on AWS](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-h3-geospatial-functions) — documentation
8. [Kontur Population: Global Population Density for 400m H3 Hexagons](https://data.humdata.org/api/3/action/package_show?id=kontur-population-dataset) — dataset
