Ogr2ogr recipes
Skill buildmoonshot/skillpacks/skills/gis/intermediate/ogr2ogr-recipes
A beginner-to-expert curriculum of drop-in skills for Claude Code, Codex, and any coding agent. Copy-paste ready, tested, not a link farm.
npx -y skills add buildmoonshot/skillpacks --skill ogr2ogr-recipesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use when converting, reprojecting, filtering, or loading vector data between formats with GDAL/OGR (ogr2ogr) — shapefile, GeoJSON, GeoPackage, PostGIS, and similar. Makes the agent use correct, safe ogr2ogr invocations instead of guessed flags, and prefer robust formats over fragile ones.
SKILL.md
1.9 KB, as published. Nobody here has run it
ogr2ogr Recipes
ogr2ogr is the fastest way to move vector data around — and easy to get subtly wrong. Use the known-good patterns.
Reproject correctly
-t_srs EPSG:xxxxtransforms to a target CRS.-s_srs EPSG:yyyysets the source CRS — needed when the source CRS is undefined or wrong. Setting-s_srsdoes not move coordinates; only-t_srstransforms them. (This is the define-vs-project distinction; seecrs-discipline.)
Pick robust formats
- Prefer GeoPackage (
-f GPKG) over shapefile: no 2 GB limit, no 10-character field-name truncation, no.dbfencoding surprises, multiple layers in one file. - Use
-nlt PROMOTE_TO_MULTIto avoid "mixed single/multi geometry" failures when a layer has both.
Load into PostGIS
ogr2ogr -f PostgreSQL "PG:host=... dbname=... user=..." input.gpkg \
-nln schema.table -nlt PROMOTE_TO_MULTI -lco GEOMETRY_NAME=geom -lco FID=id
Filter on the way through
- Attributes:
-where "status = 'active'" - Bounding box:
-spat xmin ymin xmax ymax - Clip to a layer:
-clipsrc clip.gpkg
Safety
- Run
ogrinfo -so <file>first to confirm layer name, CRS, geometry type, and feature count — and again after, to verify. -makevalidrepairs geometry in transit; use-skipfailuresonly when you understand what's being skipped (and report how many).
Why this matters
A guessed ogr2ogr command often "succeeds" while silently truncating field names, dropping the CRS, mangling encoding, or skipping features. The recipes above make the common conversions correct and verifiable instead of hopeful.