Claude-skill-registry h3-pg
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/h3-pg" ~/.claude/skills/majiayu000-claude-skill-registry-h3-pg && rm -rf "$T"
manifest:
skills/data/h3-pg/SKILL.mdsource content
h3-pg PostgreSQL Extension
Extension Architecture
Two extensions:
— Core H3 bindings (indexing, traversal, hierarchy, inspection,CREATE EXTENSION h3
operator). No PostGIS dependency.<->
— PostGIS integration (geometry/geography casts,CREATE EXTENSION h3_postgis
operator, polygon fill, raster helpers). Requires@
and optionallypostgis
.postgis_raster
Postgres-Specific H3 Features
These exist only in h3-pg, not other H3 language bindings.
Direct casts (
h3_postgis):
→ cell centroid as POINT, SRID 4326h3index::geometry
→ cell centroid as POINT, SRID 4326h3index::geography
Operators:
— grid distance in cells between two h3index values (a <-> b
)h3
— index geometry/geography at resolution (geom @ resolution
)h3_postgis
Operator classes for
h3index: BTREE, HASH, BRIN, SP-GIST (h3)
Boundary helpers (
h3_postgis):
→ polygon with SRID 4326, splits at antimeridianh3_cell_to_boundary_geometry(h3index)
→ geography polygon, splits at antimeridianh3_cell_to_boundary_geography(h3index)
Polygon fill (
h3_postgis):
→ SETOF h3indexh3_polygon_to_cells(geometry, resolution)
→ SETOF h3indexh3_polygon_to_cells(geography, resolution)
Raster integration (
h3_postgis, requires postgis_raster):
— per-cell stats (count, sum, mean, stddev, min, max)h3_raster_summary(raster, resolution, [band])
— clips raster by cell boundariesh3_raster_summary_clip(...)
— uses cell centroids, avoids pentagon edge casesh3_raster_summary_centroids(...)
— for cells smaller than pixelsh3_raster_summary_subpixel(...)
— discrete class counts per cellh3_raster_class_summary*(...)
Tile helper (
h3_postgis):
— returns optimal H3 resolution for XYZ tile zoom levelh3_get_resolution_from_tile_zoom(z, [max_h3_resolution=15], [min_h3_resolution], [hex_edge_pixels=44], [tile_size=512])
, targeting hexagons approximatelyz
wide on screenhex_edge_pixels
Common Pattern Fixes
| Pattern | DO NOT | DO |
|---|---|---|
| Get centroid | | |
| Get boundary with SRID | | |
| Distance check (meters) | | |
| Grid distance (cells) | | |
Antimeridian gotcha: Cells crossing 180° are split into valid polygons.
ST_Centroid of a split polygon may fall outside the cell — use h3::geometry for centroids instead.
Critical v3 → v4 Renames
| v3 Name (DO NOT USE) | v4 Replacement |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
/ | |
/ | |
Unit parameters (v4): Area and length functions now take a
unit text parameter:
— useh3_get_hexagon_area_avg(resolution, [unit = 'km^2'])
or'km^2''m^2'
— useh3_get_hexagon_edge_length_avg(resolution, [unit = 'km'])
or'km''m'
— exact area for specific cellh3_cell_area(cell, [unit = 'km^2'])
— exact length for specific edgeh3_edge_length(edge, [unit = 'km'])
Spelling change (v4.2.3+): Prefer
h3_latlng_to_cell over h3_lat_lng_to_cell (underscore version deprecated). Same for h3_cell_to_latlng, h3_vertex_to_latlng.
Documentation
- API reference: https://github.com/zachasme/h3-pg/blob/main/docs/api.md
- v3→v4 migration: https://h3geo.org/docs/library/migration-3.x/functions