kendrick-oppong/geoskills/spatial-indexing-strategy

Claude Code and agent skill by kendrick-oppong/geoskills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when deciding how to index or partition spatial data for query performance — R-tree vs quadtree vs geohash vs H3 vs S2, database spatial indexes, and when to denormalize location into a discrete grid cell for sharding, caching keys, or aggregation.

Install

npx vskill@latest install kendrick-oppong/geoskills/spatial-indexing-strategy

SKILL.md

The same SKILL.md was published earlier as kendrick-oppong/geoskills/spatial-indexing-strategy.

Spatial Indexing Strategy

When to use this skill

  • "This spatial query is slow" (before reaching for hardware)
  • Choosing a grid system for aggregation, caching keys, sharding, or "nearby" lookups
  • Designing a schema that will hold millions+ of geometries

Decision framework

MechanismBest forNotes
R-tree (PostGIS GiST, SQLite R*Tree)General-purpose bounding-box index on arbitrary geometry (points, lines, polygons)Default choice inside a relational database; use for ST_Intersects, ST_DWithin, bbox filters
QuadtreeHierarchical spatial subdivision, tile pyramids, client-side spatial trees (e.g. in-browser clustering)Natural fit for tile-based web maps; used internally by many tiling tools
GeohashString-prefix-based proximity, sortable spatial keys in a plain key-value store (Redis, DynamoDB)Cheap to implement; has "edge" discontinuity artifacts near boundaries — two nearby points can have very different prefixes
H3 (Uber)Hexagonal global grid for aggregation, binning, and analytics (e.g. "trips per hex per hour")Hexagons have uniform neighbor distance/adjacency, unlike geohash's rectangular cells — better for spatial statistics and heatmaps
S2 (Google)Global cell hierarchy for very large-scale, precision-sensitive indexing (e.g. global coverage systems)More complex API, strong for polygon coverage approximation at web scale
Grid-based sharding keyPartitioning a huge table/cluster by regionPick cell size so shards are balanced by data density, not raw area — dense urban cells need finer partitioning than sparse rural ones

Checklist

  • [ ] Is there a spatial index on the geometry column at all? (CREATE INDEX ... USING GIST in PostGIS) — the single highest-leverage fix for slow spatial queries
  • [ ] Are you comparing geometry (geometry type, planar) or geography (geography type, ellipsoidal) — geography indexes/queries are more expensive; use geometry + a projected CRS if raw speed matters and the area is regional, not global
  • [ ] Is the query pattern "nearest neighbor"? Use a KNN-aware index/operator (PostGIS <->), not a brute-force ORDER BY ST_Distance
  • [ ] Is the query pattern "aggregate by area" (heatmaps, choropleths, density)? Precompute an H3/grid join rather than doing live polygon aggregation per request
  • [ ] For a cache or NoSQL key design, does the chosen grid resolution match the query radius? Too coarse = large fan-out per lookup; too fine = many cells to union for a wide search radius
  • [ ] Are indexes actually being used? Check the query plan (EXPLAIN ANALYZE) — a common miss is wrapping the indexed column in a function, which defeats the index unless a matching functional index exists

Common pitfalls

  • Missing GiST index entirely: the most common root cause of "PostGIS is slow" — always check first.
  • Geography type used for regional-only data: geography computes on a spheroid and is noticeably slower than geometry + local projection for area-bounded apps (e.g. a single-country dashboard).
  • KNN via `ORDER BY ST_Distance(...) LIMIT n` without the `<->` operator: forces a full table scan instead of an index-assisted nearest-neighbor search.
  • Geohash boundary discontinuity: two points a meter apart on opposite sides of a geohash cell boundary can share zero prefix characters — don't use raw geohash proximity for "find nearby" without also querying neighbor cells.
  • Over-fine H3 resolution for the data density: aggregating sparse rural data at a fine hex resolution produces mostly-empty cells and wastes storage/compute — resolution should match feature density, ideally chosen per-region.

Reference snippets

sql
CREATE INDEX idx_places_geom ON places USING GIST (geom);
-- KNN: nearest 10 places to a point, index-assisted
SELECT id FROM places ORDER BY geom <-> ST_SetSRID(ST_MakePoint(:lon, :lat), 4326) LIMIT 10;
python
import h3
cell = h3.latlng_to_cell(lat, lon, 9) # resolution 9 hex, ~0.1 km2 — pick per use case

Related skills

  • postgis-geospatial — indexing inside PostgreSQL specifically
  • duckdb-spatial-geoparquet — indexing/partitioning strategy for analytical/columnar workloads
  • webgis-performance-optimization — client-side spatial data structures (quadtrees for clustering, etc.)

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/kendrick-oppong/geoskills/spatial-indexing-strategy/badge)](https://verified-skill.com/skills/kendrick-oppong/geoskills/spatial-indexing-strategy)

Something wrong with this skill or its page? Tell us.