Skip to content

Instantly share code, notes, and snippets.

@wuhland
Last active June 21, 2023 08:06
Show Gist options
  • Select an option

  • Save wuhland/e058c4c224a94bba253a to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

for i in *.shp is preferable

@Elindorath
Copy link
Copy Markdown

Isn't the two echo inverted?

@lgylym
Copy link
Copy Markdown

lgylym commented Nov 29, 2020

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

@mgrondo1
Copy link
Copy Markdown

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