I have a PostgreSQL database hosted on a Windows 2008 Server RT Virtual Machine (Yes I know it should be hosted on a Linux VM but this is what my organization has dictated it be on. Sigh...)
Our GIS guys dump a lot of shapefiles into a repository. We would like to have an autoprocess that walks through folder as a scheduled task. We would like to add these into our Postgres geodatabase for some other processes we are currently developing
I am looking to walk through large amounts of shapefiles and have their geometries and file names loaded into out database.
Here's the gist of the core portions of the ingest function I have working so far
import os, subprocess
base_dir = r"c:\shape_file_repository"
full_dir = os.walk(base_dir)
shapefile_list = []
for source, dirs, files in full_dir:
for file_ in files:
if file_[-3:] == 'shp':
#print "Found Shapefile"
shapefile_path = base_dir + '/' + file_
shapefile_list.append(shapefile_path)
for paths in shapefile_list:
#This is the part where I keep running into trouble. os.system also didnt work
temp_bat = open(r"c:\temp\temp_shp.bat", "w")
temp_bat.write(r'start /D c:\Program Files (x86)\PostgreSQL\8.4\bin\shp2pgsql.exe' + \
paths + "new_shp_table | psql -d geometry_database")
temp_bat.close()
subprocess.Popen(r"c:\temp\temp_shp.bat")
Once the geometries are loaded into the new database table I already have code setup to pull the geometry out of the temporary table and load that plus the shapefile name into our main database table. My problem is I can do this through command prompt, however running the windows commands through python or outputting them to batch file and then running them does not seem to be working at all.