Skip to content

Instantly share code, notes, and snippets.

@oeon
Last active October 13, 2015 08:58
Show Gist options
  • Save oeon/4171529 to your computer and use it in GitHub Desktop.
Save oeon/4171529 to your computer and use it in GitHub Desktop.
Add column with source filename from folder of shapefiles. Requires GDAL 1.10dev, my attempt to drop .shp extension isn't working - but overall, works.
for f in *.shp;
do
name=${f%.shp}
/Users/you/gdal_trunk/bin/ogrinfo $f -sql "ALTER TABLE $name ADD COLUMN filename character(21)"
/Users/you/gdal_trunk/bin/ogrinfo $f -dialect SQLite -sql "UPDATE $name SET filename = '$f'"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment