Agent skill
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 this agent skill to your Project
npx add-skill https://github.com/postgis/h3-pg/tree/main/docs
SKILL.md
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). Requirespostgisand optionallypostgis_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 4326h3index::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)
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 antimeridianh3_cell_to_boundary_geography(h3index)→ geography polygon, splits at antimeridian
Polygon fill (h3_postgis):
h3_polygon_to_cells(geometry, resolution)→ SETOF h3indexh3_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 boundariesh3_raster_summary_centroids(...)— uses cell centroids, avoids pentagon edge casesh3_raster_summary_subpixel(...)— for cells smaller than pixelsh3_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 levelz, targeting hexagons approximatelyhex_edge_pixelswide on screen
Common Pattern Fixes
| Pattern | DO NOT | DO |
|---|---|---|
| Get centroid | ST_Centroid(h3_cell_to_boundary_geometry(h3)) |
h3::geometry |
| Get boundary with SRID | h3_cell_to_boundary(h3)::geometry |
h3_cell_to_boundary_geometry(h3) |
| Distance check (meters) | ST_Distance(a.h3::geography, b.h3::geography) <= N |
ST_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.
Critical v3 → v4 Renames
| v3 Name (DO NOT USE) | v4 Replacement |
|---|---|
h3_geo_to_h3 |
h3_latlng_to_cell |
h3_to_geo |
h3_cell_to_latlng |
h3_to_geo_boundary |
h3_cell_to_boundary |
h3_k_ring |
h3_grid_disk |
h3_k_ring_distances |
h3_grid_disk_distances |
h3_hex_ring |
h3_grid_ring_unsafe |
h3_line |
h3_grid_path_cells |
h3_distance |
h3_grid_distance |
h3_to_parent |
h3_cell_to_parent |
h3_to_children |
h3_cell_to_children |
h3_compact |
h3_compact_cells |
h3_uncompact |
h3_uncompact_cells |
h3_polyfill |
h3_polygon_to_cells |
h3_indexes_are_neighbors |
h3_are_neighbor_cells |
h3_hex_area |
h3_get_hexagon_area_avg |
h3_hex_area_km2 / h3_hex_area_m2 |
h3_get_hexagon_area_avg(res, unit) |
h3_edge_length_km / h3_edge_length_m |
h3_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 cellh3_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
- API reference: https://github.com/postgis/h3-pg/blob/main/docs/api.md
- v3→v4 migration: https://h3geo.org/docs/library/migration-3.x/functions
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
setup-timescaledb-hypertables
Use this skill when creating database schemas or tables for Timescale, TimescaleDB, TigerData, or Tiger Cloud, especially for time-series, IoT, metrics, events, or log data. Use this to improve the performance of any insert-heavy table. **Trigger when user asks to:** - Create or design SQL schemas/tables AND Timescale/TimescaleDB/TigerData/Tiger Cloud is available - Set up hypertables, compression, retention policies, or continuous aggregates - Configure partition columns, segment_by, order_by, or chunk intervals - Optimize time-series database performance or storage - Create tables for sensors, metrics, telemetry, events, or transaction logs **Keywords:** CREATE TABLE, hypertable, Timescale, TimescaleDB, time-series, IoT, metrics, sensor data, compression policy, continuous aggregates, columnstore, retention policy, chunk interval, segment_by, order_by Step-by-step instructions for hypertable creation, column selection, compression policies, retention, continuous aggregates, and indexes.
postgres-hybrid-text-search
Use this skill to implement hybrid search combining BM25 keyword search with semantic vector search using Reciprocal Rank Fusion (RRF). **Trigger when user asks to:** - Combine keyword and semantic search - Implement hybrid search or multi-modal retrieval - Use BM25/pg_textsearch with pgvector together - Implement RRF (Reciprocal Rank Fusion) for search - Build search that handles both exact terms and meaning **Keywords:** hybrid search, BM25, pg_textsearch, RRF, reciprocal rank fusion, keyword search, full-text search, reranking, cross-encoder Covers: pg_textsearch BM25 index setup, parallel query patterns, client-side RRF fusion (Python/TypeScript), weighting strategies, and optional ML reranking.
design-postgres-tables
Use this skill for general PostgreSQL table design. **Trigger when user asks to:** - Design PostgreSQL tables, schemas, or data models when creating new tables and when modifying existing ones. - Choose data types, constraints, or indexes for PostgreSQL - Create user tables, order tables, reference tables, or JSONB schemas - Understand PostgreSQL best practices for normalization, constraints, or indexing - Design update-heavy, upsert-heavy, or OLTP-style tables **Keywords:** PostgreSQL schema, table design, data types, PRIMARY KEY, FOREIGN KEY, indexes, B-tree, GIN, JSONB, constraints, normalization, identity columns, partitioning, row-level security Comprehensive reference covering data types, indexing strategies, constraints, JSONB patterns, partitioning, and PostgreSQL-specific best practices.
find-hypertable-candidates
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.
migrate-postgres-tables-to-hypertables
Use this skill to migrate identified PostgreSQL tables to Timescale/TimescaleDB hypertables with optimal configuration and validation. **Trigger when user asks to:** - Migrate or convert PostgreSQL tables to hypertables - Execute hypertable migration with minimal downtime - Plan blue-green migration for large tables - Validate hypertable migration success - Configure compression after migration **Prerequisites:** Tables already identified as candidates (use find-hypertable-candidates first if needed) **Keywords:** migrate to hypertable, convert table, Timescale, TimescaleDB, blue-green migration, in-place conversion, create_hypertable, migration validation, compression setup Step-by-step migration planning including: partition column selection, chunk interval calculation, PK/constraint handling, migration execution (in-place vs blue-green), and performance validation queries.
design-postgis-tables
Comprehensive PostGIS spatial table design reference covering geometry types, coordinate systems, spatial indexing, and performance patterns for location-based applications
Didn't find tool you were looking for?