Skip to content

Instantly share code, notes, and snippets.

@stiles
Created December 6, 2016 12:01
Show Gist options
  • Save stiles/596f0b8419173cfc337a082753e6a45b to your computer and use it in GitHub Desktop.
Save stiles/596f0b8419173cfc337a082753e6a45b to your computer and use it in GitHub Desktop.
Merge multiple shapefiles (year to year, for example) and append attribute table to include original file name (for categorization)
for f in *.shp
do
base=${f%.shp}
ogrinfo $f -sql "ALTER TABLE $base ADD COLUMN filename character(15)"
ogrinfo $f -dialect SQLite -sql "UPDATE $base SET filename = '$base'"
ogr2ogr -update -append merged.shp $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment