DuckDB Spatial Skill
H3 hexagonal indexing, PostGIS-compatible spatial queries, and geographic analysis with GF(3) coloring.
Best use case
DuckDB Spatial Skill is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
H3 hexagonal indexing, PostGIS-compatible spatial queries, and geographic analysis with GF(3) coloring.
Teams using DuckDB Spatial Skill should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/duckdb-spatial/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How DuckDB Spatial Skill Compares
| Feature / Agent | DuckDB Spatial Skill | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
H3 hexagonal indexing, PostGIS-compatible spatial queries, and geographic analysis with GF(3) coloring.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# DuckDB Spatial Skill
H3 hexagonal indexing, PostGIS-compatible spatial queries, and geographic analysis with GF(3) coloring.
## Trigger
- Spatial SQL queries, geographic data analysis
- H3 hexagonal grid operations
- Point-in-polygon, distance queries
- Geospatial joins, spatial indexing
## GF(3) Trit: 0 (Ergodic/Coordinator)
Coordinates spatial data flow and transforms between coordinate systems.
## Installation
```sql
INSTALL spatial;
LOAD spatial;
-- Also useful
INSTALL h3 FROM community;
LOAD h3;
```
## Core Spatial Types
```sql
-- Point, LineString, Polygon, MultiPoint, etc.
SELECT ST_Point(-122.4194, 37.7749) as san_francisco;
SELECT ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))') as square;
-- GeoJSON parsing
SELECT ST_GeomFromGeoJSON('{"type":"Point","coordinates":[-122.4,37.7]}');
```
## Colored Spatial Table Schema
```sql
CREATE TABLE geo_features (
feature_id VARCHAR PRIMARY KEY,
name VARCHAR,
geometry GEOMETRY,
feature_type VARCHAR,
-- GF(3) coloring
seed BIGINT,
gay_color VARCHAR,
gf3_trit INTEGER,
-- Metadata
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert with color derivation
INSERT INTO geo_features VALUES (
'sf-001',
'San Francisco',
ST_Point(-122.4194, 37.7749),
'city',
4815162342, -- seed
'#DC6B3B', -- gay_color
1, -- trit (+1)
CURRENT_TIMESTAMP
);
```
## H3 Hexagonal Indexing
```sql
-- Convert lat/lon to H3 index at resolution 9
SELECT h3_latlng_to_cell(37.7749, -122.4194, 9) as h3_index;
-- Get cell boundary as polygon
SELECT h3_cell_to_boundary_wkt(h3_latlng_to_cell(37.7749, -122.4194, 9));
-- Get neighbors (k-ring)
SELECT h3_grid_disk(h3_latlng_to_cell(37.7749, -122.4194, 9), 1) as neighbors;
-- Color H3 cells
CREATE TABLE h3_colored AS
SELECT
h3_latlng_to_cell(lat, lon, 9) as h3_index,
COUNT(*) as point_count,
-- Color from H3 index
h3_latlng_to_cell(lat, lon, 9) % 3 - 1 as gf3_trit
FROM points
GROUP BY 1;
```
## Spatial Queries with Color
```sql
-- Find all features within 10km of a point
SELECT
f.name,
f.gay_color,
f.gf3_trit,
ST_Distance_Spheroid(f.geometry, ST_Point(-122.4194, 37.7749)) / 1000 as dist_km
FROM geo_features f
WHERE ST_DWithin_Spheroid(
f.geometry,
ST_Point(-122.4194, 37.7749),
10000 -- 10km in meters
)
ORDER BY dist_km;
-- Spatial join with GF(3) balance check
SELECT
a.name as region,
COUNT(*) as point_count,
SUM(b.gf3_trit) as trit_sum,
SUM(b.gf3_trit) % 3 as gf3_balance
FROM regions a
JOIN points b ON ST_Contains(a.geometry, b.geometry)
GROUP BY a.name;
```
## Coordinate Reference Systems
```sql
-- Transform between CRS
SELECT ST_Transform(
ST_Point(-122.4194, 37.7749),
'EPSG:4326', -- WGS84
'EPSG:3857' -- Web Mercator
) as web_mercator;
-- Area calculation in proper units
SELECT ST_Area(
ST_Transform(geometry, 'EPSG:4326', 'EPSG:32610') -- UTM Zone 10N
) / 1e6 as area_km2
FROM regions;
```
## GeoParquet Integration
```sql
-- Read GeoParquet files
SELECT * FROM read_parquet('cities.parquet');
-- Write with geometry
COPY (SELECT * FROM geo_features) TO 'features.parquet' (FORMAT PARQUET);
-- Create spatial index
CREATE INDEX geo_features_spatial_idx ON geo_features USING RTREE (geometry);
```
## Example: Colored City Analysis
```python
import duckdb
import hashlib
def seed_from_string(s: str) -> int:
return int(hashlib.sha256(s.encode()).hexdigest()[:16], 16) & 0x7FFFFFFFFFFFFFFF
def analyze_cities_with_color(cities_geojson):
conn = duckdb.connect()
conn.execute("INSTALL spatial; LOAD spatial;")
conn.execute("""
CREATE TABLE cities AS
SELECT
name,
ST_GeomFromGeoJSON(geometry) as geom,
population
FROM read_json_auto(?)
""", [cities_geojson])
# Add colors
conn.execute("""
ALTER TABLE cities ADD COLUMN seed BIGINT;
ALTER TABLE cities ADD COLUMN gay_color VARCHAR;
ALTER TABLE cities ADD COLUMN gf3_trit INTEGER;
""")
# Update with deterministic colors
cities = conn.execute("SELECT name FROM cities").fetchall()
for (name,) in cities:
seed = seed_from_string(name)
hue = seed % 360
trit = 1 if (hue < 60 or hue >= 300) else (0 if hue < 180 else -1)
conn.execute("""
UPDATE cities SET seed = ?, gf3_trit = ? WHERE name = ?
""", [seed, trit, name])
return conn
# Query with spatial + color
conn.execute("""
SELECT
name,
gf3_trit,
ST_X(geom) as lon,
ST_Y(geom) as lat,
population
FROM cities
WHERE ST_DWithin_Spheroid(geom, ST_Point(-122, 37), 500000)
ORDER BY population DESC
""")
```
## Triads
```
duckdb-spatial (0) ⊗ geodesic-manifold (-1) ⊗ geohash-coloring (+1) = 0 ✓
duckdb-spatial (0) ⊗ osm-topology (-1) ⊗ map-projection (+1) = 0 ✓
```
## References
- [DuckDB Spatial Extension](https://duckdb.org/docs/extensions/spatial)
- [H3 Hexagonal Grid](https://h3geo.org/)
- PostGIS DocumentationRelated Skills
fswatch-duckdb
FileSystemWatcher over /tmp with DuckDB/DuckLake persistence. Auto-starts on Amp sessions for resilient file monitoring with temporal queries.
duckdb-timetravel
Layer 3: Temporal Versioning and ACSet Schema Generation for DuckDB
duckdb-quadruple-interleave
Chaotic interleaving across local DuckDB databases modeled as coupled quadruple pendula. Random walks both BETWEEN databases and WITHIN tables for context injection.
duckdb-ies
Layer 4: IES Interactome Analytics with GF(3) Momentum Tracking
duckdb-temporal-versioning
Temporal versioning and interaction history with time-travel queries, causality tracking, and deterministic replay
zx-calculus
Coecke's ZX-calculus for quantum circuit reasoning via string diagrams with Z-spiders (green) and X-spiders (red)
zulip-cogen
Zulip Cogen Skill 🐸⚡
zls-integration
zls-integration skill
zig
zig skill
zig-syrup-bci
Multimodal BCI pipeline in Zig: DSI-24 EEG, fNIRS mBLL, eye tracking IVT, LSL sync, EDF read/write, GF(3) conservation
zig-programming
zig-programming skill
zeroth-bot
Zeroth Bot - 3D-printed open-source humanoid robot platform for sim-to-real and RL research. Affordable entry point for humanoid robotics.