Skip to content

h3

H3 bindings for PostgreSQL

Overview

PackageVersionCategoryLicenseLanguage
pg_h34.5.0GISApache-2.0C
IDExtensionBinLibLoadCreateTrustRelocSchema
1530h3NoYesNoYesNoYes-
1531h3_postgisNoYesNoYesNoYes-

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

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY4.5.01817161514pg_h3-
RPMPIGSTY4.5.01817161514h3-pg_$v-
DEBPIGSTY4.5.01817161514postgresql-$v-h3-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

Build

You can build the RPM / DEB packages for pg_h3 using pig build:

pig build pkg pg_h3         # build RPM / DEB packages

Install

You can install pg_h3 directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

Install
pig install pg_h3;          # Install for current active PG version
pig
pig ext install -y pg_h3 -v 18  # PG 18
pig ext install -y pg_h3 -v 17  # PG 17
pig ext install -y pg_h3 -v 16  # PG 16
pig ext install -y pg_h3 -v 15  # PG 15
pig ext install -y pg_h3 -v 14  # PG 14
dnf
dnf install -y h3-pg_18       # PG 18
dnf install -y h3-pg_17       # PG 17
dnf install -y h3-pg_16       # PG 16
dnf install -y h3-pg_15       # PG 15
dnf install -y h3-pg_14       # PG 14
apt
apt install -y postgresql-18-h3   # PG 18
apt install -y postgresql-17-h3   # PG 17
apt install -y postgresql-16-h3   # PG 16
apt install -y postgresql-15-h3   # PG 15
apt install -y postgresql-14-h3   # PG 14

Create Extension:

CREATE EXTENSION h3;

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.

ALTER EXTENSION h3 UPDATE TO '4.5.0';

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.

CREATE EXTENSION h3;
SET h3.strict = true;

SELECT h3_latlng_to_cell(POINT(-122.0553238, 37.3615593), 5);
SELECT h3_cell_to_latlng('85283473fffffff'::h3index);
SELECT h3_cell_to_boundary('85283473fffffff'::h3index);

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

TaskFunctions
Inspect identifiersh3_get_resolution, h3_get_base_cell_number, h3_is_valid_cell, h3_is_valid_index, h3_is_pentagon
Traverse neighborhoodsh3_grid_disk, h3_grid_disk_distances, h3_grid_ring, h3_grid_path_cells, h3_grid_distance
Change resolutionh3_cell_to_parent, h3_cell_to_children, h3_cell_to_center_child, h3_compact_cells, h3_uncompact_cells
Cover regionsh3_polygon_to_cells, h3_cells_to_multi_polygon
Directed edgesh3_cells_to_directed_edge, h3_directed_edge_to_cells, h3_reverse_directed_edge
Vertices and measurementsh3_cell_to_vertexes, h3_vertex_to_latlng, h3_cell_area, h3_edge_length, h3_great_circle_distance
Explicit cell componentsh3_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.

SELECT h3_grid_disk('85283473fffffff'::h3index, 2);
SELECT h3_grid_ring('85283473fffffff'::h3index, 1);
SELECT h3_cell_to_parent('85283473fffffff'::h3index, 3);

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.

CREATE TABLE locations (cell h3index);
CREATE INDEX locations_cell_btree ON locations (cell);
CREATE INDEX locations_cell_gist ON locations
USING gist (cell h3index_gist_ops_experimental);

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?