Skip to content

Instantly share code, notes, and snippets.

@wuhland
Last active June 21, 2023 08:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wuhland/e058c4c224a94bba253a to your computer and use it in GitHub Desktop.
Save wuhland/e058c4c224a94bba253a 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.

@jeff-predictwise
Copy link

for i in *.shp is preferable

@Elindorath
Copy link

Isn't the two echo inverted?

@lgylym
Copy link

lgylym commented Nov 29, 2020

For future references, I find ogrmerge really handy to use.

@mgrondo1
Copy link

Isn't the two echo inverted?

Yes they are...

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