PostGIS scripts
From Geomoose
Contents |
Background
Make this a bat file and schedule to run. This will update a PostGIS database spatial table with a shapefile. I have a bat file for each layer to be updated and this is called from a seperate bat file. The commeted out section allows you to interactively add layers through the command window
Requirements
The name of the tables must match and be present in the PostGIS database. The field names must match. You may heve variables set to point at the GDAL libraries. I did not so I creat the pointers in this bat file.
bat file example
@ECHO OFF
REM Import a single shapefile to a PG layer of the same name REM Variables; customize as needed SET PATH=C:\ms4w\tools\gdal-ogr;%PATH% SET SHAPEFILEDIR=C:\Shapefiles Path SET PG_CONNECT_STRING=PG:"port=5432 dbname=databasename user=username password=password" SET GEOMETRYCOL=the_geom SET IDCOL=gid SET SRID=EPSG:2914
set PATH=\ms4w\Apache\cgi-bin;\ms4w\tools\gdal-ogr;\ms4w\tools\mapserv;\ms4w\tools\shapelib;\ms4w\proj\bin;\ms4w\tools\shp2tile;\ms4w\tools\shpdiff;\ms4w\tools\avce00;\ms4w\tools\demtools;%PATH% REM echo GDAL, mapserv, PROJ, and shapelib dll paths set
set GDAL_DATA=\ms4w\gdaldata REM echo GDAL_DATA path set
set GDAL_DRIVER_PATH=\ms4w\gdalplugins REM echo GDAL_DRIVER_PATH set
set PROJ_LIB=\ms4w\proj\nad REM echo PROJ_LIB set
REM Fixed layer name:
REM SET LAYER=layer name
REM Interactive prompt: REM SET /p LAYER="Enter layer name (name of shapefile without .shp): " SET LAYER=layer name
REM To simply view information about a layer: REM OGRINFO.EXE %SHAPEFILEDIR% %LAYER% -so REM PAUSE REM OGRINFO.EXE %PG_CONNECT_STRING% %LAYER% -so REM PAUSE
@ECHO ON OGR2OGR.EXE -overwrite -lco GEOMETRY_NAME=%GEOMETRYCOL% -nlt GEOMETRY -a_srs %SRID% -f "PostgreSQL" %PG_CONNECT_STRING% %SHAPEFILEDIR% %LAYER%
OGRINFO.EXE %PG_CONNECT_STRING% -sql "ALTER TABLE %LAYER% RENAME COLUMN ogc_fid TO %IDCOL%"
@ECHO OFF REM PAUSE
Notes
Contributed by Steve