Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Convert worldclim climate data to cloud optimized geotif

http://www.worldclim.org/current

wget http://biogeo.ucdavis.edu/data/climate/worldclim/1_4/grid/cur/tmin_30s_bil.zip
wget http://biogeo.ucdavis.edu/data/climate/worldclim/1_4/grid/cur/tmax_30s_bil.zip
wget http://biogeo.ucdavis.edu/data/climate/worldclim/1_4/grid/cur/tmean_30s_bil.zip
wget http://biogeo.ucdavis.edu/data/climate/worldclim/1_4/grid/cur/prec_30s_bil.zip

unzip tmin_30s_bil.zip
unzip tmax_30s_bil.zip
unzip tmean_30s_bil.zip
unzip prec_30s_bil.zip

mkdir tmp
mkdir clouded
for i in *.bil; do
    base=`basename $i .bil`
    gdalwarp -co TILED=YES -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 -co COMPRESS=LZW -co ZLEVEL=9 -co TFW=NO $i tmp/$base.tif
    gdaladdo -r nearest tmp/$base.tif 2 4 8 16 32
    gdal_translate -co TILED=YES -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 -co COMPRESS=LZW -co ZLEVEL=9 -co TFW=NO -co COPY_SRC_OVERVIEWS=YES tmp/$base.tif clouded/$base.tif
    rm tmp/$base.tif
done
rmdir tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment