Merge Subdirectories of Shapefiles Using OGR
As a follow-up to my post “Merge A Directory of Shapefiles Using OGR,” I came across a similar problem today. I had a bunch of data in subfolders inside a parent folder. I wanted to merge all of these shapefiles into one, without manually moving them into a single directory (and since they all had the same name, that would also require renaming them all). The technique discussed in my previous post needed a very minor tweak to make things work perfectly. Here it is:
for /R %f in (*.shp) do (
if not exist merged\merged.shp (
ogr2ogr -f “esri shapefile” merged\merged.shp %f) else (
ogr2ogr -f “esri shapefile” -update -append merged\merged.shp %f -nln Merged )
That’s it! That little “/R” makes it recursively pump through all subdirectories! Magic :)
Posted: May 18th, 2010 under GIS.