Changes between Initial Version and Version 1 of UsersWikiBatchLoadShapefilesForWindowsUsingShp2pgsql


Ignore:
Timestamp:
Nov 7, 2010, 2:20:54 AM (13 years ago)
Author:
aperi2007
Comment:

Start of page with a batch procedure for windows to load shapefiles on postgres.

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiBatchLoadShapefilesForWindowsUsingShp2pgsql

    v1 v1  
     1'''Procedure to batch load shapefiles on window pc'''[[BR]]
     2
     3I have often many shapefiles to load on postgres/postgis.[[BR]]
     4Even 50, 100 shapefile every time.[[BR]]
     5So I will need a procedure to load all simply on a windows 7 machine.
     6[[BR]]
     7This batch file is my simply but very useful solution.
     8[[BR]]
     9Create a file named "load_shapefiles.bat" and put this code:
     10
     11----
     12
     13{{{
     14REM *******************************************************************
     15REM ** Simple batch procedure for Windows shell-dos (Win7 compatible)**
     16REM ** for batch load of a list of shapefiles on a Postgres/Postgis  **
     17REM ** database.                                                     **
     18REM **                                                               **
     19REM ** usage:                                                        **                                 
     20REM ** Create a directory for the shapefiles                         **
     21REM ** Create a directory for the resulting sql-files                **
     22REM ** Set the variable PATH_SHP with the path forward the shapefiles**
     23REM ** Set the variable PATH_PSQL forward the psql.exe               **
     24REM ** Set the variable PATH_SHP2SQL forward the sh2pgsql.exe        **
     25REM ** Set the variable PATH_SQL with the path forward the directory **
     26REM **         where will be output the sql files                    **
     27REM ** Set the pghost variale with the address of the server Postgres**
     28REM ** Set the pgport variable with the port of the istance postgres **
     29REM ** Set the pgdb variable with the database target                **
     30REM ** Set the pggeom variable with the name to usage for the        **
     31REM **         "geometry" field will be create                       **
     32REM ** Set the pgencoding variable with the Encoding to use          **
     33REM ** Set the pgschema variable with the target schema for tables   **
     34REM ** Set the pgtable variale with av optionally prefix to apply    **
     35REM **         to all the tables will be create                      **
     36REM ** Set the pguser variable with the user account                 **
     37REM ** Set the pgpassword with the password for the account          **
     38REM **                                                               **
     39REM ** After all these setting (whew....)                            **
     40REM ** Fortunately all these settings will remain for all other loads**
     41REM **         you will need to do :)                                **
     42REM ** open a shell dos and launch                                   **
     43REM ** load_shapefiles.bat                                           **
     44REM ** and wait for the result .... :)                               **
     45REM **                                                               **
     46REM *******************************************************************
     47
     48set PATH_SHP=D:\dbtopo\tools_postgres\procedura_caricamento_shapefiles\shapefiles
     49set PATH_PSQL=C:\Program Files (x86)\PostgreSQL\9.0\bin\psql.exe
     50set PATH_SHP2SQL=C:\Program Files (x86)\PostgreSQL\9.0\bin\shp2pgsql.exe
     51set PATH_SQL=D:\dbtopo\tools_postgres\procedura_caricamento_shapefiles\sql
     52
     53set pghost=localhost
     54set pgport=5432
     55set pgdb=dblotto2
     56set pgsrid=3003
     57set pggeom=geom
     58set pgencoding="UTF-8"
     59
     60set pgschema=public
     61set pgtable_prefix="_____"
     62
     63set pguser=dbtopowrite
     64set pgpassword=dbtopowrite
     65
     66
     67REM "Scan shapefile and create the SQL file"
     68for %%f in (%PATH_SHP%\*.shp) do "%PATH_SHP2SQL%" -s %pgsrid% -d -g %pggeom% -D -i -I -W %pgencoding% %%f %pgschema%.%pgtable_prefix%_%%~nf > %PATH_SQL%\%%~nf.sql
     69
     70REM "Scan the SQL file and load them in the DB Postgres"
     71for %%f in (%PATH_SQL%\*.sql) do "%PATH_PSQL%" -h %pghost% -p %pgport% -d %pgdb% -L %%~nxf.log -U %pguser% -f %%f
     72
     73REM "Scan the SQL files and remove all them (to return to the original configuration in the file-system"
     74for %%f in (%PATH_SQL%\*.sql) do del %%f
     75
     76 
     77}}}
     78
     79----
     80
     81Regards to all,
     82
     83Andrea Peri.