[GRASS-SVN] r52188 - grass/branches/develbranch_6/scripts/r.blend
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jun 23 01:27:10 PDT 2012
Author: hamish
Date: 2012-06-23 01:27:10 -0700 (Sat, 23 Jun 2012)
New Revision: 52188
Modified:
grass/branches/develbranch_6/scripts/r.blend/r.blend
Log:
add flag to output single image;
allow percent to be floating point;
clean up variable names and quoting;
change to default percentage to useful value.
Modified: grass/branches/develbranch_6/scripts/r.blend/r.blend
===================================================================
--- grass/branches/develbranch_6/scripts/r.blend/r.blend 2012-06-22 10:51:33 UTC (rev 52187)
+++ grass/branches/develbranch_6/scripts/r.blend/r.blend 2012-06-23 08:27:10 UTC (rev 52188)
@@ -42,13 +42,18 @@
#%end
#%option
#% key: percent
-#% type: integer
-#% answer: 2
-#% options : 0-99
+#% type: double
+#% answer: 50
+#% options : 0-100
#% description: Percentage weight of first map for color blending
#% required : no
#%end
+#% flag
+#% key: c
+#% description: Combine resulting R,G,B layers into single output map
+#%end
+
if [ -z "$GISBASE" ] ; then
echo "You must be in GRASS GIS to run this program." 1>&2
exit 1
@@ -64,39 +69,57 @@
exec g.parser "$0" "$@"
fi
+FIRST="$GIS_OPT_FIRST"
+SECOND="$GIS_OPT_SECOND"
+OUTPUT="$GIS_OPT_OUTPUT"
+PERCENT="$GIS_OPT_PERCENT"
+
if [ "$GRASS_OVERWRITE" != 1 ] ; then
for MAP in r g b ; do
- g.findfile elem=cell file=${GIS_OPT_OUTPUT}.$MAP > /dev/null
+ g.findfile elem=cell file="$OUTPUT.$MAP" > /dev/null
if [ $? -eq 0 ] ; then
- g.message -e "Raster map <${GIS_OPT_OUTPUT}.$MAP> already exists."
+ g.message -e "Raster map <$OUTPUT.$MAP> already exists."
exit 1
fi
done
fi
-PERC_INV=`expr 100 - $GIS_OPT_PERCENT`
+PERC_INV=`echo "$PERCENT" | awk '{printf("%.6g", 100.0 - $1)}'`
g.message "Calculating the three component maps..."
-r.mapcalc "$GIS_OPT_OUTPUT.r = r#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 - .$GIS_OPT_PERCENT) * r#${GIS_OPT_SECOND}; \
- $GIS_OPT_OUTPUT.g = g#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 - .$GIS_OPT_PERCENT) * g#${GIS_OPT_SECOND}; \
- $GIS_OPT_OUTPUT.b = b#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 - .$GIS_OPT_PERCENT) * b#$GIS_OPT_SECOND"
+r.mapcalc "$OUTPUT.r = r#$FIRST * $PERCENT/100.0 + (1.0 - $PERCENT/100.0) * r#$SECOND ; \
+ $OUTPUT.g = g#$FIRST * $PERCENT/100.0 + (1.0 - $PERCENT/100.0) * g#$SECOND ; \
+ $OUTPUT.b = b#$FIRST * $PERCENT/100.0 + (1.0 - $PERCENT/100.0) * b#$SECOND"
g.message "Setting color tables to grey..."
# this must be "0 black \n 255 white"
for MAP in r g b ; do
- r.colors map=${GIS_OPT_OUTPUT}.$MAP col=grey255
- r.support map=${GIS_OPT_OUTPUT}.$MAP title="Color blend of $GIS_OPT_FIRST and $GIS_OPT_SECOND" \
- history=""
- r.support map=${GIS_OPT_OUTPUT}.$MAP history="r.blend \"$MAP\" channel."
- r.support map=${GIS_OPT_OUTPUT}.$MAP history=" ${GIS_OPT_PERCENT}% of $GIS_OPT_FIRST, ${PERC_INV}% of $GIS_OPT_SECOND"
+ r.colors map="$OUTPUT.$MAP" col=grey255
+ r.support map="$OUTPUT.$MAP" title="Color blend of $FIRST and $SECOND" \
+ history="" description="generated by r.blend"
+ r.support map="$OUTPUT.$MAP" history="r.blend \"$MAP\" channel."
+ r.support map="$OUTPUT.$MAP" \
+ history=" $PERCENT% of $FIRST, $PERC_INV% of $SECOND"
+ r.support map="$OUTPUT.$MAP" history=""
+ # write cmd history:
+ r.support map="$OUTPUT.$MAP" history="${CMDLINE}"
done
-# write cmd history:
-r.support ${GIS_OPT_OUTPUT}.r history="${CMDLINE}"
-r.support ${GIS_OPT_OUTPUT}.g history="${CMDLINE}"
-r.support ${GIS_OPT_OUTPUT}.b history="${CMDLINE}"
-g.message "Done. Use the following command to visualize the result:"
-g.message message="d.rgb r=${GIS_OPT_OUTPUT}.r g=${GIS_OPT_OUTPUT}.g b=${GIS_OPT_OUTPUT}.b"
+if [ $GIS_FLAG_C -eq 1 ] ; then
+ r.composite r="$OUTPUT.r" g="$OUTPUT.g" b="$OUTPUT.b" output="$OUTPUT"
+ r.support map="$OUTPUT" title="Color blend of $FIRST and $SECOND" \
+ history="" description="generated by r.blend"
+ r.support map="$OUTPUT" \
+ history="$PERCENT% of $FIRST, $PERC_INV% of $SECOND"
+ r.support map="$OUTPUT" history=""
+ r.support map="$OUTPUT" history="${CMDLINE}"
+
+ g.remove --quiet rast="$OUTPUT.r,$OUTPUT.g,$OUTPUT.b"
+else
+ g.message "Done. Use the following command to visualize the result:"
+ g.message message="d.rgb r=$OUTPUT.r g=$OUTPUT.g b=$OUTPUT.b"
+fi
+
exit 0
More information about the grass-commit
mailing list