Skip to content

Instantly share code, notes, and snippets.

@allixender
Created October 29, 2022 12:17
Show Gist options
  • Save allixender/e33ac8bec2bd8484ca7329154839a729 to your computer and use it in GitHub Desktop.
Save allixender/e33ac8bec2bd8484ca7329154839a729 to your computer and use it in GitHub Desktop.
Make proper GeoTiff COG with overviews through GDAL
#!/bin/bash
# https://trac.osgeo.org/gdal/wiki/CloudOptimizedGeoTIFF
input=$1
output=$2
oversample="nearest" # or nearest, average
gdal_translate $1 interm_step1.tif -co TILED=YES -co COMPRESS=DEFLATE
gdaladdo -r $oversample interm_step1.tif 2 4 8 16 32
gdal_translate interm_step1.tif $2 -co TILED=YES -co COMPRESS=LZW -co COPY_SRC_OVERVIEWS=YES \
-co BIGTIFF=IF_SAFER -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 --config GDAL_TIFF_OVR_BLOCKSIZE 512
rm interm_step1.tif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment