[GRASS-SVN] r63304 - in grass/trunk: raster/r.his scripts/r.shadedmap

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Nov 30 14:25:52 PST 2014


Author: wenzeslaus
Date: 2014-11-30 14:25:52 -0800 (Sun, 30 Nov 2014)
New Revision: 63304

Modified:
   grass/trunk/raster/r.his/main.c
   grass/trunk/scripts/r.shadedmap/r.shadedmap.html
   grass/trunk/scripts/r.shadedmap/r.shadedmap.py
Log:
r.his and r.shade(edmap): propagate all NULLs by default, flag for NULLs color from color table, option for constant color for NULLs

Modified: grass/trunk/raster/r.his/main.c
===================================================================
--- grass/trunk/raster/r.his/main.c	2014-11-30 21:54:53 UTC (rev 63303)
+++ grass/trunk/raster/r.his/main.c	2014-11-30 22:25:52 UTC (rev 63304)
@@ -19,6 +19,7 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/display.h>
+#include <grass/colors.h>
 #include "his.h"
 #include <grass/glocale.h>
 
@@ -45,6 +46,9 @@
     int g_used;
     int b_file = 0;
     int b_used;
+    int bg_r, bg_g, bg_b;
+    int bgcolor_state;
+    int draw_nulls;  /* 0 as nulls, 1 draw using bgcolor, 2 draw from table */
     struct Cell_head window;
     struct Colors hue_colors;
     struct Colors int_colors;
@@ -54,6 +58,7 @@
     struct GModule *module;
     struct Option *opt_h, *opt_i, *opt_s;
     struct Option *opt_r, *opt_g, *opt_b;
+    struct Option *bgcolor;
     struct Flag *nulldraw;
 
     G_gisinit(argv[0]);
@@ -111,13 +116,34 @@
     opt_b->gisprompt = "new,cell,raster";
     opt_b->description = _("Name of output layer to be used for blue");
 
+    bgcolor = G_define_standard_option(G_OPT_C_BG);
+    bgcolor->label = _("Color to use instead of NULL values");
+    bgcolor->answer = NULL;
+
     nulldraw = G_define_flag();
-    nulldraw->key = 'n';
-    nulldraw->description = _("Respect NULL values while drawing");
+    nulldraw->key = 'c';
+    nulldraw->description = _("Use colors from color tables for NULL values");
 
+    G_option_exclusive(bgcolor, nulldraw, NULL);
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+    draw_nulls = 0;
+    if (nulldraw->answer) {
+        draw_nulls = 2;
+    }
+    if (bgcolor->answer) {
+        bgcolor_state = G_str_to_color(bgcolor->answer, &bg_r, &bg_g, &bg_b);
+        if (bgcolor_state == 1) {
+                draw_nulls = 1;
+        } else if (bgcolor_state == 2) {
+            /* none is the same as not providing the color */
+            draw_nulls = 0;
+        } else {
+            G_fatal_error(_("No such color <%s>"), bgcolor->answer);
+        }
+    }
 
     /* read in current window */
     G_get_window(&window);
@@ -220,15 +246,24 @@
 	    Rast_get_row_colors(sat_file, atrow, &sat_colors, sat_r, dummy, dummy, sat_n);
 
 	for (atcol = 0; atcol < window.cols; atcol++) {
-	    if (nulldraw->answer) {
-		if (hue_n[atcol]
-		    || (int_used && int_n[atcol])
-		    || (sat_used && sat_n[atcol])) {
+	    if (hue_n[atcol]
+                || (int_used && int_n[atcol])
+                || (sat_used && sat_n[atcol]))
+		{
+		    if (draw_nulls == 0) {
+			/* write nulls where nulls are by default */
 		    Rast_set_c_null_value(&r_array[atcol], 1);
 		    Rast_set_c_null_value(&g_array[atcol], 1);
 		    Rast_set_c_null_value(&b_array[atcol], 1);
 		    continue;
+		} else if (draw_nulls == 1) {
+			/* if nulls opaque and bgcolor provided use it */
+			r_array[atcol] = bg_r;
+			g_array[atcol] = bg_g;
+			b_array[atcol] = bg_b;
+			continue;
 		}
+		/* else use the color table colors, G6 default */
 	    }
 
 	    if (int_used)

Modified: grass/trunk/scripts/r.shadedmap/r.shadedmap.html
===================================================================
--- grass/trunk/scripts/r.shadedmap/r.shadedmap.html	2014-11-30 21:54:53 UTC (rev 63303)
+++ grass/trunk/scripts/r.shadedmap/r.shadedmap.html	2014-11-30 22:25:52 UTC (rev 63304)
@@ -16,7 +16,16 @@
 <a href="r.slope.aspect.html">r.slope.aspect</a> or
 <a href="r.shaded.relief.html">r.shaded.relief</a><br>.
 
+<p>
+NULL values are propagated by default, so if any of the two input rasters
+contains NULL cell NULL will be also in the output. If <b>-c</b> flag is
+used and cell in <b>drapemap</b> raster is NULL, just <b>reliefmap</b>
+color is used. If cell in <b>reliefmap</b> raster is NULL, shading effect
+is not applied and original colors are used. If <b>bgcolor</b> option is
+used, NULL value in any input raster will be in the output replaced
+by the given color.
 
+
 <h2>NOTES</h2>
 
 Refer to the <a href="r.his.html">r.his</a> help page for more details;

Modified: grass/trunk/scripts/r.shadedmap/r.shadedmap.py
===================================================================
--- grass/trunk/scripts/r.shadedmap/r.shadedmap.py	2014-11-30 21:54:53 UTC (rev 63303)
+++ grass/trunk/scripts/r.shadedmap/r.shadedmap.py	2014-11-30 22:25:52 UTC (rev 63304)
@@ -42,8 +42,26 @@
 #% options: -99-99
 #% answer: 0
 #%end
+#%option
+#% key: bgcolor
+#% type: string
+#% key_desc: name
+#% label: Color to use instead of NULL values
+#% description: Either a standard color name, R:G:B triplet, or "none"
+#% gisprompt: old,color_none,color
+#%end
+#%flag
+#% key: c
+#% description: Use colors from color tables for NULL values
+#%end
+#%rules
+#% exclusive: bgcolor, -c
+#%end
 
+# TODO: bgcolor is not using standard option because it has default white
+# using `answer:` will cause `default:` which is not the same as no default
 
+
 import os
 from grass.script import core as gcore
 from grass.script import raster as grast
@@ -57,13 +75,20 @@
 
 
 def main():
-    options, unused = gcore.parser()
+    options, flags = gcore.parser()
 
     drape_map = options['drapemap']
     relief_map = options['reliefmap']
     brighten = int(options['brighten'])
     output_map = options['output']
+    bgcolor = options['bgcolor']
 
+    rhis_extra_args = {}
+    if bgcolor:
+        rhis_extra_args['bgcolor'] = bgcolor
+    if flags['c']:
+        rhis_extra_args['flags'] = 'c'
+
     to_remove = []
     try:
         unique_name = 'tmp__rshadedmap_%d' % os.getpid()
@@ -86,7 +111,7 @@
             relief_map = relief_map_tmp
             to_remove.append(relief_map_tmp)
         gcore.run_command('r.his', hue=drape_map, intensity=relief_map,
-                          red=tmp_r, green=tmp_g, blue=tmp_b)
+                          red=tmp_r, green=tmp_g, blue=tmp_b, **rhis_extra_args)
         to_remove.extend([tmp_r, tmp_g, tmp_b])
         gcore.run_command('r.composite', red=tmp_r, green=tmp_g,
                           blue=tmp_b, output=output_map)
@@ -94,7 +119,7 @@
     except CalledModuleError, error:
         remove(to_remove)
         # TODO: implement module name to CalledModuleError
-        gcore.fatal(_("Module %s failed. Check the above error messages.") % error.args)
+        gcore.fatal(_("Module %s failed. Check the above error messages.") % error.cmd)
 
 
 if __name__ == "__main__":



More information about the grass-commit mailing list