[GRASS-SVN] r33561 - in grass/trunk/scripts: r.blend v.db.join

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Sep 26 20:06:45 EDT 2008


Author: glynn
Date: 2008-09-26 20:06:45 -0400 (Fri, 26 Sep 2008)
New Revision: 33561

Added:
   grass/trunk/scripts/r.blend/r.blend.py
Modified:
   grass/trunk/scripts/v.db.join/v.db.join.py
Log:
Convert r.blend to Python
Fix bug in v.db.join


Added: grass/trunk/scripts/r.blend/r.blend.py
===================================================================
--- grass/trunk/scripts/r.blend/r.blend.py	                        (rev 0)
+++ grass/trunk/scripts/r.blend/r.blend.py	2008-09-27 00:06:45 UTC (rev 33561)
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:	r.blend for GRASS 5.7; based on blend.sh for GRASS 5
+# 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
+#
+#		This program is free software under the GNU General Public
+#		License (>=v2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+#############################################################################
+
+#%Module
+#%  description: Blends color components of two raster maps by a given ratio.
+#%  keywords: raster
+#%End
+#%option
+#% key: first
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Name of first raster map for blending
+#% key_desc : name
+#% required : yes
+#%end
+#%option
+#% key: second
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Name of second raster map for blending
+#% key_desc : name
+#% required : yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% description: Base name for red, green and blue output maps containing the blend
+#% key_desc : name
+#% required : yes
+#%end
+#%option
+#% key: percent
+#% type: integer
+#% answer: 50
+#% options : 1-99
+#% description: Percentage weight of first map for color blending
+#% required : no
+#%end
+
+import sys
+import os
+import string
+import grass
+
+def main():
+    first = options['first']
+    second = options['second']
+    output = options['output']
+    percent = options['percent']
+
+    mapset = grass.gisenv()['MAPSET']
+
+    if not grass.overwrite():
+	for ch in ['r','g','b']:
+	    map = '%s.%s' % (output, ch)
+	    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
+
+    frac1 = percent / 100.0
+    frac2 = perc_inv / 100.0
+
+    grass.message("Calculating the three component maps...")
+    template = string.Template("$output.$$ch = $frac1 * $$ch#$first + $frac2 * $$ch#$second")
+    s = template.substitute(output = output,
+			    first = first, second = second,
+			    frac1 = frac1, frac2 = frac2)
+    template = string.Template(s)
+    for ch in ['r','g','b']:
+	map = "%s.%s" % (output, ch)
+	grass.run_command('r.mapcalc', expr = template.substitute(ch = ch))
+	grass.run_command('r.colors', map = map, color = 'grey255')
+	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 = 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 __name__ == "__main__":
+    options, flags = grass.parser()
+    main()


Property changes on: grass/trunk/scripts/r.blend/r.blend.py
___________________________________________________________________
Name: svn:executable
   + *

Modified: grass/trunk/scripts/v.db.join/v.db.join.py
===================================================================
--- grass/trunk/scripts/v.db.join/v.db.join.py	2008-09-26 21:13:14 UTC (rev 33560)
+++ grass/trunk/scripts/v.db.join/v.db.join.py	2008-09-27 00:06:45 UTC (rev 33561)
@@ -60,6 +60,7 @@
 import sys
 import os
 import subprocess
+import string
 import grass
 
 def main():
@@ -95,7 +96,7 @@
     cols = [l.split(':') for l in s.splitlines() if l.startswith('Column ')]
 
     select = "SELECT $colname FROM $otable WHERE $otable.$ocolumn=$table.$column"
-    template = Template("UPDATE $table SET $colname=(%s);" % select)
+    template = string.Template("UPDATE $table SET $colname=(%s);" % select)
 
     for col in cols:
 	colname = col[0]



More information about the grass-commit mailing list