[Gdal-dev] ogr2ogr hundreds of shapefiles

Martel, Christian Christian.Martel at drdc-rddc.gc.ca
Thu Apr 26 14:09:36 EDT 2007


Matt,

Thanks. It is what I was looking for (a windows script).
However, "(" and ")" were not correct in the if clause and it lacks the
-nln parameter in else clause.

Here is the correct script :

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

Christian

> -----Original Message-----
> From: Matt Wilkie [mailto:matt.wilkie at gov.yk.ca] 
> Sent: 26 avril 2007 12:05
> To: Martel, Christian
> Cc: gdal-dev at lists.maptools.org
> Subject: Re: [Gdal-dev] ogr2ogr hundreds of shapefiles
> 
> 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