[GRASS-SVN] r52189 - grass/trunk/scripts/r.blend

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 23 01:42:15 PDT 2012


Author: hamish
Date: 2012-06-23 01:42:14 -0700 (Sat, 23 Jun 2012)
New Revision: 52189

Modified:
   grass/trunk/scripts/r.blend/r.blend.py
Log:
add flag to output single image; allow percent to be floating point (merge from devbr6)


Modified: grass/trunk/scripts/r.blend/r.blend.py
===================================================================
--- grass/trunk/scripts/r.blend/r.blend.py	2012-06-23 08:27:10 UTC (rev 52188)
+++ grass/trunk/scripts/r.blend/r.blend.py	2012-06-23 08:42:14 UTC (rev 52189)
@@ -6,7 +6,7 @@
 # AUTHOR(S):	CERL?; updated to GRASS 5.7 by Michael Barton
 #               Converted to Python by Glynn Clements
 # PURPOSE:	To redraw current displayed maps to 24 bit PNG output
-# COPYRIGHT:	(C) 2004 by the GRASS Development Team
+# COPYRIGHT:	(C) 2004-2012 by the GRASS Development Team
 #
 #		This program is free software under the GNU General Public
 #		License (>=v2). Read the file COPYING that comes with GRASS
@@ -35,13 +35,18 @@
 #%end
 #%option
 #% key: percent
-#% type: integer
+#% type: double
 #% answer: 50
-#% options : 1-99
+#% 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
 
+
 import sys
 import os
 import string
@@ -61,8 +66,8 @@
 	    if grass.find_file(map, element = 'cell', mapset = mapset)['file']:
 		grass.fatal(_("Raster map <%s> already exists.") % map)
 
-    percent = int(percent)
-    perc_inv = 100 - percent
+    percent = float(percent)
+    perc_inv = 100.0 - percent
 
     frac1 = percent / 100.0
     frac2 = perc_inv / 100.0
@@ -81,17 +86,33 @@
     for ch in ['r','g','b']:
 	map = "%s.%s" % (output, ch)
 	grass.run_command('r.colors', map = map, color = 'grey255')
+	grass.run_command('r.support', map = map, history="",
+			  title = "Color blend of %s and %s" % (first, second),
+			  description = "generated by r.blend")
 	grass.run_command('r.support', map = map,
-			  title = "Color blend of %s and %s" % (first, second), history="")
-	grass.run_command('r.support', map = map,
 			  history = "r.blend %s channel." % ch)
 	grass.run_command('r.support', map = map,
 			  history = "  %d%% of %s, %d%% of %s" % (percent, first, perc_inv, second))
+	grass.run_command('r.support', map = output, history = "")
 	grass.run_command('r.support', map = map, history = os.environ['CMDLINE'])
 
-    grass.message(_("Done. Use the following command to visualize the result:"))
-    grass.message(_("d.rgb r=%s.r g=%s.g b=%s.b") % (output, output, output))
 
+    if flags['c']:
+        grass.run_command('r.composite', r = '%s.r' % output,
+	    g = '%s.g' % output, b = '%s.b' % output, output = output)
+
+	grass.run_command('r.support', map = output, history="",
+	    title = "Color blend of %s and %s" % (first, second),
+	    description = "generated by r.blend")
+	grass.run_command('r.support', map = output,
+	    history = "  %d%% of %s, %d%% of %s" % (percent, first, perc_inv, second))
+	grass.run_command('r.support', map = output, history = "")
+	grass.run_command('r.support', map = output, history = os.environ['CMDLINE'])
+    else:
+        grass.message(_("Done. Use the following command to visualize the result:"))
+        grass.message(_("d.rgb r=%s.r g=%s.g b=%s.b") % (output, output, output))
+
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()



More information about the grass-commit mailing list