[Gdal-dev] ogr2ogr hundreds of shapefiles

Matt Wilkie matt.wilkie at gov.yk.ca
Thu Apr 26 12:05:06 EDT 2007


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.) ?

To complement Howard's script, here is what will work in a Windows cmd 
shell (double % to put in a script, %f --> %%f):

  mkdir merged
  for %f in (*wetland*.shp) do (
    (if not exist merged\wetlands.shp ogr2ogr -f "esri shapefile" 
merged\wetlands.shp %f) else (
    ogr2ogr -f "esri shapefile" -update -append merged\wetlands.shp %f
    )
  )

The trick is to use the first input to create a new shapefile, and 
thereafter only update and append. See the end of 
http://www.gdal.org/ogr/drv_shapefile.html

cheers,

-- 
matt wilkie
--------------------------------------------
Geographic Information,
Information Management and Technology,
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------




More information about the Gdal-dev mailing list