Skip to content

Instantly share code, notes, and snippets.

@andrewharvey
Created December 17, 2015 06:06
Show Gist options
  • Save andrewharvey/09f1b77f64c6f529e266 to your computer and use it in GitHub Desktop.
Save andrewharvey/09f1b77f64c6f529e266 to your computer and use it in GitHub Desktop.
Merge many Shape files together using ogr2ogr
#!/bin/bash
dest_dir="output"
dest_layer="shape_file"
mkdir -p "${dest_dir}"
i=0
for src_file in source/*.shp ; do
echo "Reading ${src_file}"
if [ $i -eq 0 ] ; then
ogr2ogr "${dest_dir}/${dest_layer}.shp" "${src_file}"
else
ogr2ogr -update -append "${dest_dir}/${dest_layer}.shp" "${src_file}" -nln "${dest_layer}"
fi
i=$((i+1))
done
echo ""
echo "Output: ${dest_dir}/${dest_layer}.shp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment