[Gdal-dev] ogr2ogr hundreds of shapefiles

Howard Butler hobu.inc at gmail.com
Thu Apr 26 10:26:20 EDT 2007


Here's a bash script that I use to bulk load a directory of  
shapefiles that have the same schema to postgis.  It could obviously  
be made smarter, but it seems to do the trick.

#!/bin/bash

# let OGR create a table from one of the files
ogr2ogr -f Postgresql PG:"host=smoke.hobu.net" -a_srs "EPSG:26915" - 
nln outputlayer first_input_shape.shp -overwrite -nlt POLYGON

# delete all the data in the table we just created (but don't delete  
the table)
ogrinfo PG:"host=smoke.hobu.net" -sql "delete  from outputlayer"

# loop through all of the shapefiles in the directory and load them
for i in $(ls *.shp); do
   ogr2ogr -f Postgresql PG:"host=smoke.hobu.net" -a_srs " EPSG: 
26915" -nln outputlayer $i -update -append -skipfailures
done



On Apr 26, 2007, at 9:05 AM, Martel, Christian wrote:

> Hi List,
>
> How can I merge hundreds of shapefiles with wildcard in input name  
> (eg.
> fileABC*.shp) ? Does ogr2ogr allow this ?
> Is it better to write a python script (opening each file, reading
> geometries, write them to output file, etc.) ?
>
> Thanks,
> Christian
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev




More information about the Gdal-dev mailing list