- Linux: bash shell
- gdal 1.11
The example problem is needing to merge 9 shapefiles. You can manually merge shapefiles using gdal by using ogr2ogr.
To create a file to merge into use the following command. This will take a shapefile and copy it to a file called merge.shp (this filename is up to you).
- ogr2ogr -f ‘ESRI Shapefile’ merge.shp filename1.shp
Then merge the following files by using:
- ogr2ogr -f ‘ESRI Shapefile’ -update -append merge.shp filename2.shp -nln merge
- ogr2ogr -f ‘ESRI Shapefile’ -update -append merge.shp filename3.shp -nln merge
To get around having to type a lot of commands I used the following script. The script assumes you are writing everything into a directory called final.
for i in $(ls *.shp)
if [ -f “$file” ]
echo “creating final/merge.shp”
ogr2ogr -f ‘ESRI Shapefile’ -update -append $file $i -nln merge
ogr2ogr -f ‘ESRI Shapefile’ $file $i