Merge A Directory of Shapefiles Using OGR
Here’s something that may seem obvious to power users of GDAL/OGR, but not to those that are just new to using these great free tools. This is something that I use on an almost daily basis, and works when a lot of other options (QGIS, Kosmo, etc.) seem to fail. Essentially, this sequence of commands will grab every shapefile in a directory, and merge them into a single file called “merged.shp” in a directory called “merged.” Of course, you can monkey with the names if you wish, and customize to your needs, but this is a basic place to start:
for %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 )
Lets hear your useful GDAL/OGR tips in the comments below!
Posted: May 7th, 2010 under GIS.