Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Forked from wuhland/MergeSHP.md
Created October 25, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gemmadlou/a3f66e84362bf054b4f84e8fc43facdd to your computer and use it in GitHub Desktop.
Save gemmadlou/a3f66e84362bf054b4f84e8fc43facdd to your computer and use it in GitHub Desktop.
Merging Shapefiles From Command Line with GDAL\OGR2OGR

First put all the shapefiles you want merged in one directory than I run this bash script in the folder

#!/bin/bash

file="./final/merge.shp"

for i in $(ls *.shp)
do

      if [ -f "$file" ]
      then
           echo "creating final/merge.shp" 
           ogr2ogr -f 'ESRI Shapefile' -update -append $file $i -nln merge
      else
           echo "merging……"
      ogr2ogr -f 'ESRI Shapefile' $file $i
fi
done

Will put the merged file in a folder named "final" and name it merge.shp. You can change the name of this folder to whatever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment