This shell script assumes that you have already installed GDAL and are converting between .KMZ files and Shapefiles with the names preserved. The specific ogr2ogr
commands can be changed as needed.
This also assumes many .KMZ files in a single directory. Kudos to Marii Nyrop.
Begin by creating a file named batch-separate-folders.sh
with the following and place it in your directory with the KMZs:
for KMZ in *.kmz; do
IDENTIFIER="$(basename ${KMZ} .kmz)"
if [ ! -d "${IDENTIFIER}" ];
then
mkdir ${IDENTIFIER}
fi
SHP="${IDENTIFIER}/${IDENTIFIER}.shp"
ogr2ogr -f 'ESRI Shapefile' ${SHP} ${KMZ}
echo "Exported ${KMZ} to ${SHP}"
done
Then run sh ./batch-separate-folders.sh
Alternately, you can place the shapefiles in a single folder. You will want to do this if batch loading files into QGIS. Simply create a file called batch-single-folder.sh
with the contents below and place it in the directory will all of your KMZs:
DIR="shapefiles"
if [ ! -d "${DIR}" ];
then
mkdir ${DIR}
fi
for KMZ in *.kmz; do
TARGET="$(basename ${KMZ} .kmz).shp"
ogr2ogr -f 'ESRI Shapefile' ${TARGET} ${KMZ}
echo "Exported ${KMX} to ${DIR}/${TARGET}"
done
Then run sh ./batch-single-folder.sh