Skip to content

Instantly share code, notes, and snippets.

@cspanring
Created August 15, 2013 14:47
Show Gist options
  • Save cspanring/6241414 to your computer and use it in GitHub Desktop.
Save cspanring/6241414 to your computer and use it in GitHub Desktop.
Shapefile to PostGIS batch import bash script
#!/bin/bash
EPSG_CODE=<EPSG_CODE>
DATABASE_NAME=<DATABASE_NAME>
DATABASE_SCHEMA=<DATABASE_SCHEMA>
DATABASE_USER=<DATABASE_USER>
for f in *.shp
do
shp2pgsql -I -s $EPSG_CODE -d $f $DATABASE_SCHEMA.`basename $f .shp` > `basename $f .shp`.sql
done
for f in *.sql
do
psql -d $DATABASE_NAME -f $f
psql -c "ALTER TABLE $DATABASE_SCHEMA.`basename $f .sql` OWNER TO $DATABASE_USER" -d $DATABASE_NAME
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment