h3
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_h3 | 4.5.0 | GIS | Apache-2.0 | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1530 | h3 | No | Yes | No | Yes | No | Yes | - |
| 1531 | h3_postgis | No | Yes | No | Yes | No | Yes | - |
| Related | postgis qdgc pg_geohash pgrouting q3c pg_polyline mobilitydb pg_eviltransform earthdistance pg_sphere |
|---|---|
| Depended By | h3_postgis |
RPM and DEB 4.5.0 statically link the pinned H3 core; point coordinates use longitude, latitude. Reindex affected h3index btree and distance-dependent indexes after upgrading.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 4.5.0 | 1817161514 | pg_h3 | - |
| RPM | PIGSTY | 4.5.0 | 1817161514 | h3-pg_$v | - |
| DEB | PIGSTY | 4.5.0 | 1817161514 | postgresql-$v-h3 | - |
Build
You can build the RPM / DEB packages for pg_h3 using pig build:
Install
You can install pg_h3 directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
h3 exposes the H3 hierarchical hexagonal grid through PostgreSQL. Its h3index type stores cell, directed-edge, and vertex identifiers. Use it to assign coordinates to cells, aggregate by resolution, and traverse neighborhoods. The extension does not require preloading.
Upgrade to 4.5.0
Install matching files before updating each database. The update automatically rebuilds affected H3 btree indexes because earlier comparators physically sorted them in the wrong order. The migration can also recompute stored distance-dependent generated columns, rebuild dependent indexes, and refresh dependent materialized views. Plan for locks, writes, and maintenance time; a library replacement alone does not perform these operations.
For manually scheduled btree rebuilds, upstream recommends dropping affected indexes before the extension update and recreating them afterward. Install the 4.5.0 package files before requesting this extension update.
Index a Location
PostgreSQL points use longitude, latitude in degrees. Do not pass projected coordinates or swap the axes. Resolution ranges from 0 to 15.
h3.strict defaults to false; enabling it rejects out-of-range coordinates. h3.extend_antimeridian controls boundary handling at the 180-degree meridian; leave it false for typical planar PostGIS operations.
Core API
| Task | Functions |
|---|---|
| Inspect identifiers | h3_get_resolution, h3_get_base_cell_number, h3_is_valid_cell, h3_is_valid_index, h3_is_pentagon |
| Traverse neighborhoods | h3_grid_disk, h3_grid_disk_distances, h3_grid_ring, h3_grid_path_cells, h3_grid_distance |
| Change resolution | h3_cell_to_parent, h3_cell_to_children, h3_cell_to_center_child, h3_compact_cells, h3_uncompact_cells |
| Cover regions | h3_polygon_to_cells, h3_cells_to_multi_polygon |
| Directed edges | h3_cells_to_directed_edge, h3_directed_edge_to_cells, h3_reverse_directed_edge |
| Vertices and measurements | h3_cell_to_vertexes, h3_vertex_to_latlng, h3_cell_area, h3_edge_length, h3_great_circle_distance |
| Explicit cell components | h3_get_index_digit, h3_construct_cell |
Version 4.5.0 adds the general identifier validator, explicit cell-component helpers, and edge reversal. Prefer the new ring API to the unsafe variant near pentagons; neighborhood row order is not guaranteed. Grid-distance and path operations can fail for distant cells or pentagonal distortion.
Operators and Indexes
Equality and ordering support btree indexes; containment and overlap use @>, <@, and &&. The <-> operator returns grid distance, with a maximum-bigint sentinel where distance calculation fails. It is not a physical distance in meters.
GiST and SP-GiST operator classes are experimental. For geometry, geography, raster, and SRID-aware workflows, use the separate h3_postgis extension. Validate polygons before converting them to cells; invalid polygons can produce undefined results or unexpectedly large output.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)