Skip to content

Instantly share code, notes, and snippets.

@fitnr
Created January 25, 2019 14:49
Show Gist options
  • Save fitnr/abe22dbc27aa3a6685c250d8543aa9b1 to your computer and use it in GitHub Desktop.
Save fitnr/abe22dbc27aa3a6685c250d8543aa9b1 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
DIR=$1
SHP=$2
TMP=$(mktemp -d)
export DIR
downsample() {
gdalwarp -q -r max -tap -tr 0.0001 0.0001 -co NUM_THREADS=2 -of VRT -overwrite "${DIR}/${1}.tif" "${TMP}/${1}.vrt"
gdal_calc.py --quiet --format gtiff --overwrite --type=Byte --NoDataValue 0 --co COMPRESS=CCITTFAX4 --co NBITS=1 -A "${TMP}/${1}.vrt" --outfile "${TMP}/${1}.tif" --calc "A == 1"
}
export -f downsample
basename -s.tif ${DIR}/*.tif | parallel -j 15 downsample
gdalbuildvrt "$TMP/overview.vrt" $TMP/*.tif
gdal_polygonize.py -f 'ESRI Shapefile' $TMP/overview.vrt "$SHP"
rm -r $TMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment