Skip to content

h3_postgis

H3 PostGIS integration

Overview

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

RPM and DEB 4.5.0 require h3, postgis and postgis_raster; point coordinates use longitude, latitude.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY4.5.01817161514pg_h3h3, postgis, postgis_raster
RPMPIGSTY4.5.01817161514h3-pg_$v-
DEBPIGSTY4.5.01817161514postgresql-$v-h3-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
el8.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
el9.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
el9.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
el10.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
el10.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
d12.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
d12.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
d13.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
d13.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
u22.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
u22.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
u24.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
u24.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
u26.x86_64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0
u26.aarch64PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0PIGSTY 4.5.0

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_postgis CASCADE;  -- requires: h3, postgis, postgis_raster

Usage

Sources:

h3_postgis bridges H3 cells with PostGIS geometry, geography, and raster. It requires h3, postgis, and postgis_raster, including for geometry-only use. Input geometries must use SRID 4326 with longitude, latitude coordinates; the functions do not reproject inputs.

Convert Points and Cells

CREATE EXTENSION h3_postgis CASCADE;
SET h3.strict = true;

SELECT h3_latlng_to_cell(
    ST_SetSRID(ST_MakePoint(-122.0553238, 37.3615593), 4326), 9
);
SELECT h3_cell_to_geometry('85283473fffffff'::h3index);
SELECT h3_cell_to_boundary_geometry('85283473fffffff'::h3index);

Transform other coordinate systems to SRID 4326 with PostGIS before calling the H3 functions. Setting an SRID label alone does not transform coordinates.

Core API

TaskFunctions
Point to cellh3_latlng_to_cell(geometry, integer), h3_latlng_to_cell(geography, integer)
Cell centerh3_cell_to_geometry, h3_cell_to_geography
Cell boundaryh3_cell_to_boundary_geometry, h3_cell_to_boundary_geography
Polygon coverageh3_polygon_to_cells, h3_cells_to_multi_polygon_geometry, h3_cells_to_multi_polygon_geography
Continuous raster summariesh3_raster_summary, h3_raster_summary_stats_agg
Categorical raster summariesh3_raster_class_summary, h3_raster_class_summary_item_agg

The geometry-to-resolution @ operator also maps a location to an H3 cell. Validate polygon inputs with ST_IsValid(); repairs through ST_MakeValid() can change topology and produce geometry collections, so retain and review polygonal components before coverage calculations. Invalid polygons have undefined behavior.

Summarize Raster Data

SELECT (summary).h3,
       (h3_raster_summary_stats_agg((summary).stats)).*
FROM (
    SELECT h3_raster_summary(rast, 8) AS summary
    FROM rasters
) AS r
GROUP BY (summary).h3;

The default summary chooses a method; explicit clip, centroid, and subpixel variants let you control how raster pixels are assigned to cells. Review the choice against raster resolution and the requested H3 resolution.

Upgrade and Boundaries

ALTER EXTENSION h3 UPDATE TO '4.5.0';
ALTER EXTENSION h3_postgis UPDATE TO '4.5.0';

The base extension update performs affected btree rebuilds and distance-dependent refreshes, so plan its maintenance window before updating the companion. Version 4.5.0 fixes restricted-search-path maintenance on PostgreSQL 17+, expression-index dump/restore, and several geometry and polygonization errors. Both extension versions should match. Install the matching 4.5.0 package files before updating either extension.

h3.extend_antimeridian should normally remain false for planar overlays. Both extensions are relocatable; ensure the schemas containing H3 and PostGIS objects are visible when issuing unqualified SQL. Neither extension requires shared preloading.

Was this page helpful?