Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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