kendrick-oppong/geoskills/postgis-geospatial

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 for geospatial SQL workflows in PostgreSQL/PostGIS — geometry vs geography choices, indexing, SRID handling, spatial joins, migrations, and query performance tuning. Relevant when the backend stack is NestJS/Node/TypeORM/Prisma over Postgres.

Install

npx vskill@latest install kendrick-oppong/geoskills/postgis-geospatial

SKILL.md

The same SKILL.md was published earlier as kendrick-oppong/geoskills/postgis-geospatial.

PostGIS

When to use this skill

  • Designing or reviewing a schema with a geometry/geography column
  • Writing or optimizing spatial SQL (ST_Intersects, ST_DWithin, ST_Within, spatial joins)
  • Debugging slow spatial queries in a production Postgres database
  • Wiring PostGIS into a Node/NestJS backend (via pg, TypeORM, Prisma, or Kysely)

Core decisions

`geometry` vs `geography`:

geometrygeography
MathPlanar (Cartesian)Spheroidal (great-circle)
SpeedFasterSlower (more expensive math)
Correct forRegional/local data with an appropriate projected CRSGlobal data, or when you want correct distances without manual reprojection
Default recommendationUse geometry + a suitable projected CRS for anything scoped to a country/regionUse geography for global-scale "distance in meters between any two points on Earth" without projection juggling

Column & naming conventions (industry-standard, keep consistent across a codebase):

  • Geometry column named geom, geography column named geog
  • Always set an explicit SRID — never leave it at 0
  • Store one geometry type per table where feasible; use GEOMETRY (generic) only when genuinely mixed

Checklist

  • [ ] GEOMETRY column has an explicit SRID (geometry(Polygon, 4326), not bare geometry)
  • [ ] GiST index exists on every geometry/geography column used in a WHERE/JOIN predicate
  • [ ] Spatial joins use the sargable operators (&&, ST_Intersects, ST_DWithin) so the planner can use the index — avoid wrapping the geometry column in a transform inside the predicate (ST_Transform(geom, x) = ... defeats the index unless a matching expression index exists)
  • [ ] For "within X meters" queries on geometry type, reproject to a metric CRS or add a bbox pre-filter (&&) before the exact distance check
  • [ ] Migrations are idempotent (CREATE EXTENSION IF NOT EXISTS postgis, IF NOT EXISTS on indexes) — critical if managed via TypeORM/Prisma migration files
  • [ ] VACUUM ANALYZE after large bulk loads so the planner has fresh statistics for spatial columns
  • [ ] Use EXPLAIN (ANALYZE, BUFFERS) to confirm index usage, not just query correctness

Common pitfalls

  • Prisma/TypeORM don't natively model PostGIS types: geometry columns typically need raw SQL migrations and $queryRaw/createQueryBuilder raw fragments for spatial predicates — plan for this rather than fighting the ORM.
  • N+1 spatial joins: looping application-side over rows to check ST_Intersects per-row instead of a single indexed SQL join.
  • Slow `ST_DWithin` because of missing bbox pre-filter on non-indexed expressions: always let the index-friendly operator run first.
  • Storing lat/lon as separate float columns "for simplicity": loses every spatial indexing and query benefit — use a real geometry/geography column even for simple point data.
  • Reprojecting inside the hot query path repeatedly: reproject once at write time and store an additional column in the target CRS if a specific fast query pattern needs it.

Reference snippets

sql
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE TABLE sites (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
geom geometry(Point, 4326) NOT NULL
);
CREATE INDEX idx_sites_geom ON sites USING GIST (geom);
-- Nearby search within 500m, index-assisted bbox pre-filter + exact geography distance
SELECT id, name FROM sites
WHERE geom && ST_Expand(ST_SetSRID(ST_MakePoint(:lon, :lat), 4326), 0.01)
AND ST_DWithin(geom::geography, ST_SetSRID(ST_MakePoint(:lon, :lat), 4326)::geography, 500);
typescript
// NestJS + raw query via TypeORM DataSource
const nearby = await dataSource.query(
`SELECT id, name, ST_AsGeoJSON(geom) as geojson FROM sites
WHERE ST_DWithin(geom::geography, ST_SetSRID(ST_MakePoint($1,$2),4326)::geography, $3)`,
[lon, lat, radiusMeters],
);

Related skills

  • spatial-indexing-strategy — index type/strategy fundamentals
  • crs-and-reprojection — SRID and datum handling
  • geospatial-api-design — exposing PostGIS query results through a REST/GraphQL API

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/postgis-geospatial/badge)](https://verified-skill.com/skills/kendrick-oppong/geoskills/postgis-geospatial)

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