forked from lmotta/scripts-for-gis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
2_rgb.sh
executable file
·87 lines (87 loc) · 2.23 KB
/
2_rgb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#
# ***************************************************************************
# Name : 2 RGB
# Description : Create file RGB (3 bands)
#
# Arguments:
# $1: Image R G B
#
# Dependencies : gdal 1.10.1 (gdal_translate)
#
# ***************************************************************************
# begin : 2015-04-24 (yyyy-mm-dd)
# copyright : (C) 2015 by Luiz Motta
# email : motta dot luiz at gmail.com
# ***************************************************************************
#
# Revisions
#
# 0000-00-00:
# - None
#
# ***************************************************************************
#
# Example:
# 2_rgb.sh LC8_229-066_20140724_LGN00.tif 6 5 4
#
# ***************************************************************************
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation; either version 2 of the License, or *
# * (at your option) any later version. *
# * *
# ***************************************************************************
#
#
calc_rbgname_img(){
local dirname=$(dirname $in_img)
local filename=$(basename $in_img)
local extension="${filename##*.}"
filename="${filename%.*}"
rbgname_img=$dirname"/"$filename"_r"$in_r"g"$in_g"b"$in_b"."$extension
}
#
msg_error(){
local name_script=$(basename $0)
echo "Usage: $name_script <image> <r> <g> <b>" >&2
echo "<image> is the image" >&2
echo "<r> Number of band for R" >&2
echo "<g> Number of band for G" >&2
echo "<b> Number of band for B" >&2
exit 1
}
#
totalargs=4
#
if [ $# -ne $totalargs ] ; then
msg_error
exit 1
fi
#
in_img=$1
in_r=$2
in_g=$3
in_b=$4
#
if [ ! -f "$in_img" ] ; then
echo "The file '$in_img' not exist" >&2
exit 1
fi
#
calc_rbgname_img
#
printf "Creating "$rbgname_img"..."
#
gdal_translate -q -co COMPRESS=LZW -b $in_r -b $in_g -b $in_b $in_img $rbgname_img
#
code=$?
if [ "$code" != 0 ]
then
exit $code
fi
#
printf "Finished.\n"
#
exit 0