Enables H3 hexagonal grid functionality within PostgreSQL, supporting spatial indexing and raster data analysis.

Install

mkdir -p .claude/skills/h3-pg && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3971" && unzip -o skill.zip -d .claude/skills/h3-pg && rm skill.zip

Installs to .claude/skills/h3-pg

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
174 chars✓ has a “when” trigger
Advanced

Key capabilities

  • Perform spatial indexing using H3 cells
  • Convert geometry and geography types to H3
  • Execute raster analysis per cell
  • Calculate grid distance between cells
  • Fill polygons with H3 cells

How it works

It provides PostgreSQL extensions that bind to the H3 library, allowing SQL-based operations on hexagonal grid cells.

Inputs & outputs

You give it
Geometry, geography, or raster data
You get back
H3 indices or spatial analysis results

When to use h3-pg

  • Implementing H3 hexagonal spatial indexing in Postgres
  • Converting geometry types to H3 cells
  • Performing spatial analysis on raster data within a database
  • Querying geographic data using H3 grid boundaries

About this skill

h3-pg PostgreSQL Extension

Extension Architecture

Two extensions:

  • CREATE EXTENSION h3 — Core H3 bindings (indexing, traversal, hierarchy, inspection, <-> operator). No PostGIS dependency.
  • CREATE EXTENSION h3_postgis — PostGIS integration (geometry/geography casts, @ operator, polygon fill, raster helpers). Requires postgis and optionally postgis_raster.

Postgres-Specific H3 Features

These exist only in h3-pg, not other H3 language bindings.

Direct casts (h3_postgis):

  • h3index::geometry → cell centroid as POINT, SRID 4326
  • h3index::geography → cell centroid as POINT, SRID 4326

Operators:

  • a <-> b — grid distance in cells between two h3index values (h3)
  • geom @ resolution — index geometry/geography at resolution (h3_postgis)

Inspection and construction helpers (h3):

  • h3_get_index_digit(cell, resolution) — inspect the digit at a 1-based resolution step
  • h3_construct_cell(resolution, base_cell_number, digits[]) — rebuild a cell from explicit components
  • h3_is_valid_index(index) — validate any H3 index mode: cell, directed edge, or vertex

Directed edge convenience (h3):

  • h3_reverse_directed_edge(edge) — returns the same directed edge with origin and destination reversed

Operator classes for h3index: BTREE, HASH, BRIN, SP-GIST (h3)

Boundary helpers (h3_postgis):

  • h3_cell_to_boundary_geometry(h3index) → polygon with SRID 4326, splits at antimeridian
  • h3_cell_to_boundary_geography(h3index) → geography polygon, splits at antimeridian

Polygon fill (h3_postgis):

  • h3_polygon_to_cells(geometry, resolution) → SETOF h3index
  • h3_polygon_to_cells(geography, resolution) → SETOF h3index

Raster integration (h3_postgis, requires postgis_raster):

  • h3_raster_summary(raster, resolution, [band]) — per-cell stats (count, sum, mean, stddev, min, max)
  • h3_raster_summary_clip(...) — clips raster by cell boundaries
  • h3_raster_summary_centroids(...) — uses cell centroids, avoids pentagon edge cases
  • h3_raster_summary_subpixel(...) — for cells smaller than pixels
  • h3_raster_class_summary*(...) — discrete class counts per cell

Tile helper (h3_postgis):

  • h3_get_resolution_from_tile_zoom(z, [max_h3_resolution=15], [min_h3_resolution], [hex_edge_pixels=44], [tile_size=512]) — returns optimal H3 resolution for XYZ tile zoom level z, targeting hexagons approximately hex_edge_pixels wide on screen

Common Pattern Fixes

PatternDO NOTDO
Get centroidST_Centroid(h3_cell_to_boundary_geometry(h3))h3::geometry
Get boundary with SRIDh3_cell_to_boundary(h3)::geometryh3_cell_to_boundary_geometry(h3)
Distance check (meters)ST_Distance(a.h3::geography, b.h3::geography) <= NST_DWithin(a.h3::geography, b.h3::geography, N)
Grid distance (cells)h3_distance(a, b)a <-> b

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.

Ring traversal gotcha: Prefer h3_grid_ring(origin, k) for rings because it handles pentagon distortion internally. Use h3_grid_ring_unsafe(origin, k) only when fail-fast behavior or ring-walk ordering matters.

Critical v3 → v4 Renames

v3 Name (DO NOT USE)v4 Replacement
h3_geo_to_h3h3_latlng_to_cell
h3_to_geoh3_cell_to_latlng
h3_to_geo_boundaryh3_cell_to_boundary
h3_k_ringh3_grid_disk
h3_k_ring_distancesh3_grid_disk_distances
h3_hex_ringh3_grid_ring_unsafe
h3_lineh3_grid_path_cells
h3_distanceh3_grid_distance
h3_to_parenth3_cell_to_parent
h3_to_childrenh3_cell_to_children
h3_compacth3_compact_cells
h3_uncompacth3_uncompact_cells
h3_polyfillh3_polygon_to_cells
h3_indexes_are_neighborsh3_are_neighbor_cells
h3_hex_areah3_get_hexagon_area_avg
h3_hex_area_km2 / h3_hex_area_m2h3_get_hexagon_area_avg(res, unit)
h3_edge_length_km / h3_edge_length_mh3_get_hexagon_edge_length_avg(res, unit)

Unit parameters (v4): Area and length functions now take a unit text parameter:

  • h3_get_hexagon_area_avg(resolution, [unit = 'km^2']) — use 'km^2' or 'm^2'
  • h3_get_hexagon_edge_length_avg(resolution, [unit = 'km']) — use 'km' or 'm'
  • h3_cell_area(cell, [unit = 'km^2']) — exact area for specific cell
  • h3_edge_length(edge, [unit = 'km']) — exact length for specific edge

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

When not to use it

  • Applications requiring non-hexagonal grid systems

Prerequisites

PostgreSQLPostGIS (for h3_postgis extension)

Limitations

  • Requires specific extension installation
  • Antimeridian splitting requires careful handling

How it compares

It enables native SQL spatial operations on H3 grids, whereas manual approaches require external processing or complex custom functions.

Compared to similar skills

h3-pg side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
h3-pg (this skill)12moNo flagsAdvanced
find-hypertable-candidates14moNo flagsIntermediate
database02moNo flagsAdvanced
inspect-database04moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

find-hypertable-candidates

timescale

Use this skill to analyze an existing PostgreSQL database and identify which tables should be converted to Timescale/TimescaleDB hypertables. **Trigger when user asks to:** - Analyze database tables for hypertable conversion potential - Identify time-series or event tables in an existing schema - Evaluate if a table would benefit from Timescale/TimescaleDB - Audit PostgreSQL tables for migration to Timescale/TimescaleDB/TigerData - Score or rank tables for hypertable candidacy **Keywords:** hypertable candidate, table analysis, migration assessment, Timescale, TimescaleDB, time-series detection, insert-heavy tables, event logs, audit tables Provides SQL queries to analyze table statistics, index patterns, and query patterns. Includes scoring criteria (8+ points = good candidate) and pattern recognition for IoT, events, transactions, and sequential data.

18

database

asnk633

Database development and operations workflow covering SQL, NoSQL, database design, migrations, optimization, and data engineering.

00

inspect-database

Juan961

Workflow para inspeccionar y auditar Supabase/Postgres sin modificar datos, entendiendo esquema, relaciones, migraciones, logs y riesgos. USE FOR: diagnóstico de estructura, inventario de tablas, análisis de dependencias, revisión de seguridad y troubleshooting de consultas.

00

sql-queries

anthropics

Write correct, performant SQL across all major data warehouse dialects (Snowflake, BigQuery, Databricks, PostgreSQL, etc.). Use when writing queries, optimizing slow SQL, translating between dialects, or building complex analytical queries with CTEs, window functions, or aggregations.

1888

fuzzy-matching

dadbodgeoff

Multi-stage fuzzy matching pipeline for entity reconciliation. PostgreSQL trigram pre-filter, salient overlap check, and multi-factor similarity scoring.

825

sql-pro

sickn33

Master modern SQL with cloud-native databases, OLTP/OLAP optimization, and advanced query techniques. Expert in performance tuning, data modeling, and hybrid analytical systems. Use PROACTIVELY for database optimization or complex analysis.

323

Search skills

Search the agent skills registry