Created
May 16, 2013 18:03
-
-
Save drwelby/5593727 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import sys | |
'''usage: pgimport [path/to/fgdb] [database] [schema.tablename] [host] [user] [pass] | |
This lets you import fgdbs into postgis tables that have views on them ''' | |
fgdb, db, target, host, user, password = sys.argv[1:] | |
# truncate the target table | |
sqlcmd = "psql" | |
sqlargs = '-U %s -p%s -h %s -d %s -c "TRUNCATE %s"' % (user, password, host, db, target) | |
print "%s %s" % (sqlcmd, sqlargs) | |
#subprocess.call(["psql", sqlargs]) | |
#ogr2ogr in append mode | |
ogrcmd = "ogr2ogr" | |
ogrargs = '-append -skipfailures -f "PostgreSQL" PG:"host=%s dbname=%s user=%s password=%s" "%s" "%s"' \ | |
% (host, db, user, password, fgdb, target) | |
print "%s %s" % (ogrcmd, ogrargs) | |
#subprocess.call(["ogr2ogr", ogrargs]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment