Last active
February 26, 2016 09:37
-
-
Save edigiacomo/3c5fc99ab7255956f3ad to your computer and use it in GitHub Desktop.
Convert ENVI file with 52 bands in 52 GeoTIFF with color table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| print_help() | |
| { | |
| echo "Usage: $0 ENVI_FILE OUTPUTDIR" | |
| echo "" | |
| echo "Convert a 52 band ENVI file in 52 GeoTiff files with colortable" | |
| } | |
| if [[ "$1" == "-h" || "$1" == "--help" ]] | |
| then | |
| print_help | |
| exit 0 | |
| elif [[ ! $# -eq 2 ]] | |
| then | |
| print_help >&2 | |
| exit 1 | |
| fi | |
| inputfile="$1" | |
| outputdir="$2" | |
| colortable="$(mktemp)" | |
| color_list=(0:255:0 255:255:0 205:205:0 190:114:0 0:255:255 114:51:172 255:0:255 0:0:0:0 200:200:200) | |
| max_list=(5 10 20 40 60 80 100 254 255) | |
| for x in {0..255} | |
| do | |
| for i in $(seq 1 "${#color_list[*]}") | |
| do | |
| idx=$(( i - 1)) | |
| color=${color_list[$idx]} | |
| max=${max_list[$idx]} | |
| if [[ $x -le $max ]] | |
| then | |
| echo "$x $color" >> $colortable | |
| break | |
| fi | |
| done | |
| done | |
| for band in {1..52} | |
| do | |
| outputfile="$outputdir/$(basename "${inputfile%%.*}.$(printf "%02d" $band).tiff")" | |
| gdaldem color-relief "$inputfile" "$colortable" "$outputfile" -b $band -of "GTiff" -alpha -exact_color_entry -co COMPRESS=DEFLATE | |
| done | |
| rm $colortable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment