Skip to content

Instantly share code, notes, and snippets.

@YKCzoli
Last active August 29, 2015 14:07
Show Gist options
  • Save YKCzoli/e05ff3ea5b07952388b8 to your computer and use it in GitHub Desktop.
Save YKCzoli/e05ff3ea5b07952388b8 to your computer and use it in GitHub Desktop.
Mexico flood waters script
#!/bin/bash
echo "Enter bands (ie 4 3 2)"
read B1 B2 B3
echo "Enter the resulting filename"
read outputname
#unzip all files in directory
for filename in *.tar
do
tar zxf $filename
done
filename=$B1$B2$B3
#project each band epsg 3857, which is web mercator
for BAND in $B1 $B2 $B3; do
gdalwarp -t_srs EPSG:3857 *$BAND.TIF $BAND-projected.tif;
done
mkdir results
for BAND in $B1 $B2 $B3; do
mv $BAND-projected.tif results
done
cd results
#combine the bands in one image
convert $B1-projected.tif $B2-projected.tif $B3-projected.tif -combine $filename.tif
#adjust the colors in two step process
convert -sigmoidal-contrast 50x15% $filename.tif $filename-adj.tif
convert -channel B -gamma 1.25 -channel G -gamma 1.25 \
-channel RGB -sigmoidal-contrast 25x25% $filename.tif $filename-corrected.tif
#convert to 8 bit for tile mill rendering
convert -depth 8 $filename-corrected.tif $filename-corrected-8bit.tif
#create a geo reference file
listgeo -tfw $B3-projected.tif
#rename the file to match our created image
mv $B3-projected.tfw $filename-corrected-8bit.tfw
#srs, rename
gdal_edit.py -a_srs EPSG:3857 $filename-corrected-8bit.tif
mv $filename-corrected-8bit.tif $outputname-projected.tif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment