h3
pg_h3 : H3 bindings for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 1530 | h3 | pg_h3 | 4.5.0 |
GIS | Apache-2.0 | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| Need By | h3_postgis |
| See Also | postgis qdgc pg_geohash pgrouting q3c pg_polyline mobilitydb pg_eviltransform earthdistance pg_sphere |
| Siblings | h3_postgis |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 4.5.0 |
18 17 16 15 14 | pg_h3 |
- |
| RPM | PIGSTY | 4.5.0 |
18 17 16 15 14 | h3-pg_$v |
- |
| DEB | PIGSTY | 4.5.0 |
18 17 16 15 14 | postgresql-$v-h3 |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| el8.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| el9.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| el9.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| el10.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| el10.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| d12.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| d12.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| d13.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| d13.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| u22.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| u22.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| u24.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| u24.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| u26.x86_64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
| u26.aarch64 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 | PIGSTY 4.5.0 |
Source
github.com/postgis/h3-pg
h3-pg-4.5.0.tar.gz h3-4.5.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
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.