Skip to content

Instantly share code, notes, and snippets.

@blacha
Last active November 6, 2021 22:30
Show Gist options
  • Select an option

  • Save blacha/29b806963337927d83925e6814f03a9f to your computer and use it in GitHub Desktop.

Select an option

Save blacha/29b806963337927d83925e6814f03a9f to your computer and use it in GitHub Desktop.
Compare GDAL Compression
#!/bin/bash
COMPRESSION=(zstd lzw deflate)
TRANSLATE_ARGS="-co NUM_THREADS=ALL_CPUS -co PREDICTOR=2"
CUID=$(id -u)
CGID=$(id -g)
# Run docker as the current user in the current diretory
function docker_gdal() {
docker run \
--user $CUID:$CGID \
--volume $PWD:$PWD \
--workdir $PWD \
--rm \
osgeo/gdal:ubuntu-small-latest $@
}
INPUT_FILES=`ls -1 input/*.tif`
mkdir -p output/
for inFile in $INPUT_FILES; do
baseFileName=$(basename $inFile)
echo "Processing $baseFileName " # $inFile ${baseFileName%.tif}
for c in ${COMPRESSION[@]}; do
echo " Compressing $baseFileName into $c"
docker_gdal gdal_translate $inFile -of COG -co COMPRESS=$c $TRANSLATE_ARGS output/${baseFileName%.tif}.$c.cog.tiff &> /dev/null
done
done
echo "Done..."
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment