Просмотр исходного кода

rename r.relief and d.shade, add r.shade, propagate NULLs in r.his

 * backport of https://trac.osgeo.org/grass/changeset/62828, https://trac.osgeo.org/grass/changeset/62845, https://trac.osgeo.org/grass/changeset/63304, https://trac.osgeo.org/grass/changeset/63305, https://trac.osgeo.org/grass/changeset/63306, and https://trac.osgeo.org/grass/changeset/63379
 * removes d.shadedmap and r.shaded.relief directories
 * preserves 'rast to raster' and 'pre to div-code-pre' changes


git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@63636 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 10 лет назад
Родитель
Сommit
7750aeb9ee

+ 11 - 10
display/d.his/d.his.html

@@ -23,9 +23,9 @@ retains the original information in terms of <em>hue</em>,
 This program can be run non-interactively or
 interactively.  It will run non-interactively if the user
 specifies on the command line the name of a map containing
-hue values (<b>h_map</b>), and the name(s) of map(s)
-containing intensity values (<b>i_map</b>) and/or
-saturation values (<b>s_map</b>).  The resulting image will
+hue values (<b>hue</b>), and the name(s) of map(s)
+containing intensity values (<b>intensity</b>) and/or
+saturation values (<b>saturation</b>).  The resulting image will
 be displayed in the active display frame on the graphics
 monitor.
 
@@ -63,9 +63,9 @@ sounds better than <i>Normalized Scaling Factor</i>.
 
 Each map cell is processed individually. First, the working
 color is set to the color of the corresponding cell in the
-map layer chosen to represent <em>HUE</em>.  Second, this
+map layer chosen to represent <em>hue</em>.  Second, this
 color is multiplied by the <em>red</em> intensity of that
-cell in the <em>INTENSITY</em> map layer.  This map layer
+cell in the <em>intensity</em> map layer.  This map layer
 should have an appropriate gray-scale color table
 associated with it. You can ensure this by using the color
 manipulation capabilities of
@@ -73,7 +73,7 @@ manipulation capabilities of
 
 Finally, the color is made somewhat gray-based on the
 <em>red</em> intensity of that cell in the
-<em>SATURATION</em> map layer.  Again, this map layer
+<em>saturation</em> map layer.  Again, this map layer
 should have a gray-scale color table associated with it.
 
 <h2>NOTES</h2>
@@ -104,13 +104,13 @@ command <em><a href="r.his.html">r.his</a></em>.
 
 
 <h2>EXAMPLE</h2>
-<h3>Spearfish dataset</h3>
 
 <div class="code"><pre>
-g.region raster=elevation.dem
-r.shaded.relief map=elevation.dem shad=elev.shad_relf
+g.region raster=elevation
+r.relief input=elevation output=elevation_shaded_relief
+
 d.mon wx0
-d.his h=elevation.dem i=elev.shad_relf brighten=50
+d.his hue=elevation intensity=elevation_shaded_relief brighten=50
 </pre></div>
 
 <h2>SEE ALSO</h2>
@@ -119,6 +119,7 @@ d.his h=elevation.dem i=elev.shad_relf brighten=50
 <a href="d.colortable.html">d.colortable</a>,
 <a href="d.frame.html">d.frame</a>,
 <a href="d.rgb.html">d.rgb</a>,
+<a href="d.shade.html">d.shade</a>,
 <a href="r.colors.html">r.colors</a>,
 <a href="r.his.html">r.his</a>,
 <a href="i.his.rgb.html">i.his.rgb</a>,

+ 7 - 7
display/d.his/main.c

@@ -67,29 +67,29 @@ int main(int argc, char **argv)
     G_add_keyword("IHS");
     module->description =
 	_("Displays the result obtained by combining "
-	  "hue, intensity, and saturation (his) values "
+	  "hue, intensity, and saturation (HIS) values "
 	  "from user-specified input raster map layers.");
 
     opt_h = G_define_option();
-    opt_h->key = "h_map";
+    opt_h->key = "hue";
     opt_h->type = TYPE_STRING;
     opt_h->required = YES;
     opt_h->gisprompt = "old,cell,raster";
-    opt_h->description = _("Name of layer to be used for HUE");
+    opt_h->description = _("Name of layer to be used for hue");
 
     opt_i = G_define_option();
-    opt_i->key = "i_map";
+    opt_i->key = "intensity";
     opt_i->type = TYPE_STRING;
     opt_i->required = NO;
     opt_i->gisprompt = "old,cell,raster";
-    opt_i->description = _("Name of layer to be used for INTENSITY");
+    opt_i->description = _("Name of layer to be used for intensity");
 
     opt_s = G_define_option();
-    opt_s->key = "s_map";
+    opt_s->key = "saturation";
     opt_s->type = TYPE_STRING;
     opt_s->required = NO;
     opt_s->gisprompt = "old,cell,raster";
-    opt_s->description = _("Name of layer to be used for SATURATION");
+    opt_s->description = _("Name of layer to be used for saturation");
 
     brighten = G_define_option();
     brighten->key = "brighten";

+ 2 - 2
display/d.thematic.area/d.thematic.area.html

@@ -25,7 +25,7 @@ for painting a legend into that file.
 <h2>EXAMPLE</h2>
 
 <div class="code"><pre>
-d.thematic.area -l map=communes3 data=pop \
+d.thematic.area -l map=communes3 column=pop \
   breaks=111393.250000,222785.500000,334177.750000 \
   colors=255:0:0,0:255:0,0:0:255,0,0,0
 </pre></div>
@@ -35,7 +35,7 @@ pop/area) and the standard deviation algorithm to calculate class
 breaks for 5 classes:
 
 <div class="code"><pre>
-d.thematic.area -l map=communes2 data=pop/area algorithm=std \
+d.thematic.area -l map=communes2 column=pop/area algorithm=std \
   nbclasses=5 colors=0:0:255,50:100:255,255:100:50,255:0:0,156:0:0
 </pre></div>
 

+ 1 - 1
gui/wxpython/core/utils.py

@@ -999,7 +999,7 @@ command2ltype = {'d.rast'         : 'raster',
                  'd.rast3d'       : '3d-raster',
                  'd.rgb'          : 'rgb',
                  'd.his'          : 'his',
-                 'd.shadedmap'    : 'shaded',
+                 'd.shade'        : 'shaded',
                  'd.legend'       : 'rastleg',
                  'd.rast.arrow'   : 'rastarrow',
                  'd.rast.num'     : 'rastnum',

+ 3 - 2
gui/wxpython/docs/wxGUI.html

@@ -168,8 +168,9 @@ d.vect, or d.grid, for example).
       <dt><img src="icons/layer-shaded-relief-add.png" alt="icon">&nbsp;
 	<em>Add shaded relief raster map layer </em></dt>
       <dd>Adds shaded relief raster map layer,
-	see <em><a href="d.shadedmap.html">d.shadedmap</a></em>.</dd>
-      
+      see <em><a href="r.relief.html">r.relief</a></em> and
+      <em><a href="d.shade.html">d.shade</a></em>.</dd>
+
       <dt><img src="icons/layer-aspect-arrow-add.png" alt="icon">&nbsp;
 	<em>Add raster arrows layer</em></dt>
       <dd>Adds map of raster cells with directional arrows drawn. Arrow

+ 5 - 2
gui/wxpython/xml/toolboxes.xml

@@ -785,8 +785,11 @@
         <label>Least cost route or flow</label>
       </module-item>
       <separator/>
-      <module-item name="r.shaded.relief">
-        <label>Shaded relief</label>
+      <module-item name="r.relief">
+        <label>Compute shaded relief</label>
+      </module-item>
+      <module-item name="r.shade">
+        <label>Apply shade to raster</label>
       </module-item>
       <separator/>
       <module-item name="r.slope.aspect">

+ 1 - 1
imagery/i.topo.corr/test_i.topo.corr_synthetic_DEM_NC.sh

@@ -45,7 +45,7 @@ solarzenith=`echo $sunangleabovehorizon | awk '{printf "%f", 90. - $1}'`
 echo "Sun position ($DATETIME): solarzenith: $solarzenith, sunazimuth: $sunazimuth"
 
 # shade relief
-r.shaded.relief input=myplane_pyr output=myplane_pyr_shaded altitude=$sunangleabovehorizon azimuth=$sunazimuth
+r.relief input=myplane_pyr output=myplane_pyr_shaded altitude=$sunangleabovehorizon azimuth=$sunazimuth
 # show raw map as shaded map
 #d.mon wx0
 #sleep 5 # this is rather annoying

+ 1 - 1
raster/Makefile

@@ -85,7 +85,7 @@ SUBDIRS = \
 	r.series \
 	r.series.accumulate \
 	r.series.interp \
-	r.shaded.relief \
+	r.relief \
 	r.sim \
 	r.slope.aspect \
 	r.solute.transport \

+ 54 - 19
raster/r.his/main.c

@@ -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 main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
     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]);
@@ -65,59 +70,80 @@ int main(int argc, char **argv)
     G_add_keyword("HIS");
     G_add_keyword("IHS");
     module->description =
-	_("Generates red, green and blue raster map layers "
+	_("Generates red, green and blue (RGB) raster map layers "
 	  "combining hue, intensity and saturation (HIS) "
 	  "values from user-specified input raster map layers.");
 
     opt_h = G_define_option();
-    opt_h->key = "h_map";
+    opt_h->key = "hue";
     opt_h->type = TYPE_STRING;
     opt_h->required = YES;
     opt_h->gisprompt = "old,cell,raster";
-    opt_h->description = _("Name of layer to be used for HUE");
+    opt_h->description = _("Name of layer to be used for hue");
 
     opt_i = G_define_option();
-    opt_i->key = "i_map";
+    opt_i->key = "intensity";
     opt_i->type = TYPE_STRING;
     opt_i->required = NO;
     opt_i->gisprompt = "old,cell,raster";
-    opt_i->description = _("Name of layer to be used for INTENSITY");
+    opt_i->description = _("Name of layer to be used for intensity");
 
     opt_s = G_define_option();
-    opt_s->key = "s_map";
+    opt_s->key = "saturation";
     opt_s->type = TYPE_STRING;
     opt_s->required = NO;
     opt_s->gisprompt = "old,cell,raster";
-    opt_s->description = _("Name of layer to be used for SATURATION");
+    opt_s->description = _("Name of layer to be used for saturation");
 
     opt_r = G_define_option();
-    opt_r->key = "r_map";
+    opt_r->key = "red";
     opt_r->type = TYPE_STRING;
     opt_r->required = YES;
     opt_r->gisprompt = "new,cell,raster";
-    opt_r->description = _("Name of output layer to be used for RED");
+    opt_r->description = _("Name of output layer to be used for red");
 
     opt_g = G_define_option();
-    opt_g->key = "g_map";
+    opt_g->key = "green";
     opt_g->type = TYPE_STRING;
     opt_g->required = YES;
     opt_g->gisprompt = "new,cell,raster";
-    opt_g->description = _("Name of output layer to be used for GREEN");
+    opt_g->description = _("Name of output layer to be used for green");
 
     opt_b = G_define_option();
-    opt_b->key = "b_map";
+    opt_b->key = "blue";
     opt_b->type = TYPE_STRING;
     opt_b->required = YES;
     opt_b->gisprompt = "new,cell,raster";
-    opt_b->description = _("Name of output layer to be used for BLUE");
+    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 @@ int main(int argc, char **argv)
 	    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)

+ 21 - 11
raster/r.his/r.his.html

@@ -41,16 +41,16 @@ the valleys.
 
 Each map cell is processed individually. First, the working
 color is set to the color of the corresponding cell in the
-map layer chosen to represent <i>HUE</i>.  Second, this
+map layer chosen to represent <i>hue</i>.  Second, this
 color is multiplied by the <i>red</i> intensity of that
-cell in the <i>INTENSITY</i> map layer.  This map layer
+cell in the <i>intensity</i> map layer.  This map layer
 should have an appropriate gray-scale color table
 associated with it. You can ensure this by using the color
 manipulation capabilities of
 <em><a href="r.colors.html">r.colors</a></em>.
 Finally, the color is made somewhat gray-based on the
 <i>red</i> intensity of that cell in the
-<i>SATURATION</i> map layer.  Again, this map layer
+<i>saturation</i> map layer.  Again, this map layer
 should have a gray-scale color table associated with it.
 
 <h2>NOTES</h2>
@@ -88,18 +88,27 @@ program <em><a href="d.his.html">d.his</a></em>.
 
 <h2>EXAMPLES</h2>
 
-Recreate the following <em>d.his</em> command using <em>r.his</em>:
+Recreate the following example for <em>d.his</em> using <em>r.his</em>.
+First, create shaded relief and show it.
+
 <div class="code"><pre>
-g.region -p raster=elevation
-r.shaded.relief map=elevation shad=elev.shad_relf
-d.his h=elevation i=elev.shad_relf brighten=50
+g.region raster=elevation
+r.relief input=elevation output=elevation_shaded_relief
+
+d.mon wx0
+d.his hue=elevation intensity=elevation_shaded_relief brighten=50
 </pre></div>
 
+Second, compute lighter version of color of shaded relief.
+Then convert from HIS model to RGB and show the result.
+
 <div class="code"><pre>
-r.mapcalc "elev.shad_relf_bright50 = #elev.shad_relf * 1.5"
-r.colors elev.shad_relf_bright50 color=grey255
-r.his h_map=elevation i_map=elev.shad_relf_bright50 r_map=esr.r g_map=esr.g bmap=esr.b
-d.rgb red=esr.r green=esr.g blue=esr.b
+r.mapcalc "elevation_shaded_relief_bright_50 = #elevation_shaded_relief * 1.5"
+r.colors elevation_shaded_relief_bright_50 color=grey255
+r.his hue=elevation intensity=elevation_shaded_relief_bright_50 red=shadedmap_r green=shadedmap_g blue=shadedmap_b
+
+d.mon wx1
+d.rgb red=shadedmap_r green=shadedmap_g blue=shadedmap_b
 </pre></div>
 
 
@@ -113,6 +122,7 @@ d.rgb red=esr.r green=esr.g blue=esr.b
 <a href="r.colors.html">r.colors</a>,
 <a href="r.composite.html">r.composite</a>,
 <a href="r.mapcalc.html">r.mapcalc</a>,
+<a href="r.shade.html">r.shade</a>,
 <a href="i.his.rgb.html">i.his.rgb</a>,
 <a href="i.rgb.his.html">i.rgb.his</a>
 </em>

+ 3 - 3
raster/r.lake/r.lake.html

@@ -92,10 +92,10 @@ g.region raster=elev_lid792_1m -p
 r.lake elev_lid792_1m coordinates=638759.3,220264.1 water_level=113.4 lake=flooding
 
 # draw resulting lake map over shaded terrain map
-r.shaded.relief elev_lid792_1m
-d.rast elev_lid792_1m.shade
+r.relief input=elev_lid792_1m output=elev_lid792_1m_shade
+d.rast elev_lid792_1m_shade
 d.rast -o flooding
-d.vect streets_wake 
+d.vect streets_wake
 d.vect bldg_cmcl_pol type=area
 </pre></div>
 

+ 1 - 1
raster/r.shaded.relief/Makefile

@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = r.shaded.relief
+PGM = r.relief
 
 LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB)
 DEPENDENCIES = $(RASTERDEP) $(GISDEP)

+ 4 - 2
raster/r.shaded.relief/main.c

@@ -1,7 +1,7 @@
 
 /****************************************************************************
  *
- * MODULE:       r.shaded.relief
+ * MODULE:       r.relief
  * AUTHOR(S):	CERL
  *               parameters standardized: Markus Neteler, 2008
  *               updates: Michael Barton, 2004
@@ -106,7 +106,9 @@ int main(int argc, char *argv[])
     module = G_define_module();
     G_add_keyword(_("raster"));
     G_add_keyword(_("elevation"));
+    G_add_keyword(_("relief"));
     G_add_keyword(_("terrain"));
+    G_add_keyword(_("hillshade"));
     module->label = _("Creates shaded relief map from an elevation map (DEM).");
     
     parm.elevation = G_define_standard_option(G_OPT_R_INPUT);
@@ -459,7 +461,7 @@ int main(int argc, char *argv[])
 
     /* writing history file */
     Rast_short_history(sr_name, "raster", &hist);
-    Rast_append_format_history(&hist, "r.shaded.relief settings:");
+    Rast_append_format_history(&hist, "r.relief settings:");
     Rast_append_format_history(&hist,
                                "altitude=%f  azimuth=%f zmult=%f  scale=%f",
 			       altitude * radians_to_degrees,

+ 22 - 10
raster/r.shaded.relief/r.shaded.relief.html

@@ -1,6 +1,6 @@
 <h2>DESCRIPTION</h2>
 
-<em>r.shaded.relief</em> creates a raster shaded relief map based on 
+<em>r.relief</em> creates a raster shaded relief map based on 
 current resolution settings and on sun altitude, azimuth, and 
 z-exaggeration values entered by the user. If no output shademap 
 name is given, the new shaded relief map is named <em>&lt;input_map
@@ -37,14 +37,14 @@ the <b>scale</b> parameter.
 
 </ol>
 
-<p><em>r.shaded.relief</em> assigns a grey-scale color table to the new 
+<p><em>r.relief</em> assigns a grey-scale color table to the new 
 shaded relief map.
 
 <h2>NOTES</h2>
 
 To visually improve the result of shade maps from low resolution elevation
 models, use <em>r.resamp.interp</em> with bilinear or bicubic method to
-resample the DEM at higher resolution. <em>r.shaded.relief</em> is then
+resample the DEM at higher resolution. <em>r.relief</em> is then
 run on the resampled DEM.
 
 <h2>EXAMPLES</h2>
@@ -54,31 +54,43 @@ dataset location is used to hillshade the elevation map:
 
 <div class="code"><pre>
 g.region raster=elevation -p
-r.shaded.relief input=elevation output=elevation.shaded
+r.relief input=elevation output=elevation_shade
 </pre></div>
 
 <center>
-<img src="r_shaded_relief.png" alt="GRASS r.shaded.relief result (subset)" border=0>
+<img src="r_relief.png" alt="GRASS r.relief result (subset)" border=0>
 <br>
-<i>r.shaded.relief: shaded elevation map (subset)</i>
+<i>r.relief: shaded elevation map (subset)</i>
 </center>
 
+Color can be added later using <em><a href="r.shade.html">r.shade</a></em>:
+<div class="code"><pre>
+r.shade reliefmap=elevation_shade drapemap=elevation output=elevation_shaded
+</pre></div>
+
 <p>In Latitude-Longitude locations (or other non-metric locations), the
 <em>scale</em> factor has to be used:
 
 <div class="code"><pre>
 # Latitude-Longitude example
-r.shaded.relief input=srtm output=srtm.shaded scale=111120
+r.relief input=srtm output=srtm_shaded scale=111120
 </pre></div>
 
 <h2>SEE ALSO</h2>
 
-<p><!-- RGB version not ported to GRASS 6 (why?):
+<p>
+<!--
+  RGB version not ported to GRASS 6 (why?):
   <em><a href="shade.clr.sh.html">shade.clr.sh</a></em><br>
- -->
+  d.shade and r.shade probably cover most of the shade.clr functionality
+  however, it is not possible to create shade+color map in one step
+  delete this note when it is solved or if it is not considered as an issue
+-->
 <em>
+<a href="d.shade.html">d.shade</a>,
 <a href="d.his.html">d.his</a>,
 <a href="g.region.html">g.region</a>,
+<a href="r.shade.html">r.shade</a>,
 <a href="r.blend.html">r.blend</a>,
 <a href="r.colors.html">r.colors</a>,
 <a href="r.mapcalc.html">r.mapcalc</a>,
@@ -89,6 +101,6 @@ r.shaded.relief input=srtm output=srtm.shaded scale=111120
 
 Jim Westervelt, U.S. Army Construction Engineering Research Laboratory
 <br>
-Markus Metz: GRASS GIS 7- enhanced fast C version of r.shaded.relief
+Markus Metz: Enhanced fast C version of r.relief for GRASS GIS 7
 
 <p><i>Last changed: $Date$</i>

raster/r.shaded.relief/r_shaded_relief.png → raster/r.relief/r_relief.png


+ 1 - 1
raster/r.texture/r.texture.html

@@ -112,7 +112,7 @@ r.mapcalc "ortho_2001_t792_1m.greylevel = ortho_2001_t792_1m"
 r.texture ortho_2001_t792_1m.greylevel prefix=ortho_texture method=asm -s 
 # display
 g.region n=221461 s=221094 w=638279 e=638694
-d.shadedmap drape=ortho_texture_ASM_0 rel=ortho_2001_t792_1m
+d.shade drape=ortho_texture_ASM_0 rel=ortho_2001_t792_1m
 </pre></div>
 
 This calculates four maps (requested texture at four orientations):

+ 2 - 2
raster/r.watershed/front/r.watershed.html

@@ -449,8 +449,8 @@ cut-off value. This only works with SFD, not with MFD.
 <p>
 Display output in a nice way
 <div class="code"><pre>
-  r.shaded.relief map=elevation.dem
-  d.shadedmap rel=elevation.dem.shade drape=rwater.basin bright=40
+  r.relief map=elevation.dem
+  d.shade rel=elevation.dem.shade drape=rwater.basin bright=40
   d.vect rwater_course color=orange
 </pre></div>
 

+ 2 - 1
scripts/Makefile

@@ -8,7 +8,7 @@ SUBDIRS = \
 	d.rast.edit \
 	d.rast.leg \
 	d.redraw \
-	d.shadedmap \
+	d.shade \
 	d.vect.thematic \
 	d.what.rast \
 	d.what.vect \
@@ -43,6 +43,7 @@ SUBDIRS = \
 	r.plane \
 	r.reclass.area \
 	r.rgb \
+	r.shade \
 	r.tileset \
 	r.unpack \
 	r3.in.xyz \

+ 1 - 1
scripts/d.shadedmap/Makefile

@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = d.shadedmap
+PGM = d.shade
 
 include $(MODULE_TOPDIR)/include/Make/Script.make
 

+ 89 - 0
scripts/d.shade/d.shade.html

@@ -0,0 +1,89 @@
+<h2>DESCRIPTION</h2>
+
+<em>d.shade</em> will drape a color raster map over a shaded relief map.
+In place of shaded relief, any raster map can be used including aspect or slope.
+The color raster map is usually an elevation raster map with colorful color
+table (as opposed to gray scale color table). However, any raster map can be
+used including categorical raster maps.
+
+<p>
+The advantage of this module is that it allows to visualize the shaded map
+without a need to create a new raster which would combine both.
+Comparing to creating shaded relief as semi-transparent overlay on
+the color raster map, this module gives result with more saturated colors.
+
+<p>
+The input for this module can be created for example using
+<a href="r.slope.aspect.html">r.slope.aspect</a> or
+<a href="r.relief.html">r.relief</a><br>.
+
+
+<h2>NOTES</h2>
+
+Refer to the <em><a href="d.his.html">d.his</a></em> help page for more details;
+<em>d.shade</em> is simply a frontend to that module.
+
+
+<h2>EXAMPLES</h2>
+
+In this example, the <tt>aspect</tt> map in the North Carolina sample
+dataset location is used to hillshade the <tt>elevation</tt> map:
+
+<div class="code"><pre>
+g.region raster=aspect -p
+d.mon wx0
+d.shade reliefmap=aspect drapemap=elevation
+</pre></div>
+
+<!--
+image generated using the example above
+display region: g.region -a n=227228 s=220895 w=631362 e=641170
+d.out.file dshade.png
+optipng -o5 dshade.png
+-->
+<center>
+<img src="dshadedmap.png" alt="Elevation with aspect shades">
+<p>
+Figure: A detail of raster created by applying shading effect of aspect
+to elevation raster map from North Carolina dataset elevation map
+<!--
+TODO: perhaps add some explanation or thoughts about aspect versus shaded
+relief such as: in this case the shades created using aspect are much sharper
+comparing to what shaded relief would give and there are some extreme values
+in some areas
+-->
+</center>
+
+In this next example, a shaded relief raster map is created
+and used to create a colorized hillshade:
+
+<div class="code"><pre>
+g.region raster=elevation
+r.relief input=elevation output=elevation_shaded_relief
+
+d.mon wx1
+d.shade reliefmap=elevation_shaded_relief drapemap=elevation
+</pre></div>
+
+Interesting visualizations can be created using different color tables for
+elevation raster map, for example using <tt>haxby</tt> color table.
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="d.his.html">d.his</a>,
+<a href="g.pnmcomp.html">g.pnmcomp</a>,
+<a href="r.shade.html">r.shade</a>,
+<a href="r.slope.aspect.html">r.slope.aspect</a>,
+<a href="r.relief.html">r.relief</a><br>
+<a href="wxGUI.nviz.html">wxGUI 3D viewer (NVIZ)</a>
+</em>
+
+
+<h2>AUTHORS</h2>
+
+Unknown; updated to GRASS 5.7 by Michael Barton
+
+<p>
+<i>Last changed: $Date$</i>

+ 17 - 31
scripts/d.shadedmap/d.shadedmap.py

@@ -2,7 +2,7 @@
 
 ############################################################################
 #
-# MODULE:        d.shadedmap
+# MODULE:        d.shade
 # AUTHOR(S):        Unknown; updated to GRASS 5.7 by Michael Barton
 #                Converted to Python by Glynn Clements
 # PURPOSE:        Uses d.his to drape a color raster over a shaded relief map
@@ -15,9 +15,12 @@
 #############################################################################
 
 #%module
-#% description: Drapes a color raster over a shaded relief map.
+#% description: Drapes a color raster over an shaded relief or aspect map.
 #% keywords: display
 #% keywords: elevation
+#% keywords: relief
+#% keywords: hillshade
+#% keywords: visualization
 #%end
 #%option G_OPT_R_INPUT
 #% key: reliefmap
@@ -25,7 +28,8 @@
 #%end
 #%option G_OPT_R_INPUT
 #% key: drapemap
-#% description: Name of raster to drape over relief raster map
+#% label: Name of raster to drape over relief raster map
+#% description: Typically, this raster is elevation or other colorful raster
 #%end
 #%option
 #% key: brighten
@@ -34,52 +38,34 @@
 #% options: -99-99
 #% answer: 0
 #%end
-#%option G_OPT_R_OUTPUT
-#% description: Create raster map from result (optional)
-#% required: no
-#%end
 
 
-import os
-import sys
-from grass.script import core as grass
+from grass.script import core as gcore
 from grass.exceptions import CalledModuleError
 
 
 def main():
+    options, unused = gcore.parser()
+
     env = gcore.gisenv()
     mon = env.get('MONITOR', None)
     if not mon:
-        gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
+        # os is needed only here
+        import os
+        if not 'GRASS_RENDER_IMMEDIATE' in os.environ:
+            gcore.fatal(_("No graphics device selected."
+                          " Use d.mon to select graphics device."))
 
     drape_map = options['drapemap']
     relief_map = options['reliefmap']
     brighten = options['brighten']
-    output_map = options['output']
-
-    if output_map:
-        tmp_base = "tmp_drape.%d" % os.getpid()
-        tmp_r = tmp_base + '.r'
-        tmp_g = tmp_base + '.g'
-        tmp_b = tmp_base + '.b'
 
-        grass.run_command('r.his', h_map = drape_map, i_map = relief_map,
-                          r_map = tmp_r, g_map = tmp_g, b_map = tmp_b)
-        grass.run_command('r.composite', red = tmp_r, green = tmp_g,
-                          blue = tmp_b, output = output_map)
-        grass.run_command('g.remove', quiet=True, flags='f',
-                          type='rast', name='%s,%s,%s' % (tmp_r, tmp_g, tmp_b))
-
-    ret = 0
     try:
-        grass.run_command('d.his', h_map=drape_map, i_map=relief_map,
+        gcore.run_command('d.his', hue=drape_map, intensity=relief_map,
                           brighten=brighten)
     except CalledModuleError:
-        ret = 1
-
-    sys.exit(ret)
+        gcore.fatal(_("Module %s failed. Check the above error messages.") % 'd.his')
 
 
 if __name__ == "__main__":
-    options, flags = grass.parser()
     main()

BIN
scripts/d.shade/dshade.png


+ 0 - 58
scripts/d.shadedmap/d.shadedmap.html

@@ -1,58 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>d.shadedmap</em> will drape a color raster map over a shaded relief map.
-
-
-<h2>NOTES</h2>
-
-Refer to the <em>d.his</em> help page for more details; <em>d.shadedmap</em>
-is simply a frontend to that module.
-<p>
-If the <b>output</b> option is given the rendering will be written to a
-new raster map. The <b>output</b> map does not respect the <b>brighten</b>
-parameter. <!-- at this time. -->
-
-<h2>EXAMPLES</h2>
-
-In this example, the <tt>aspect</tt> map in the North Carolina sample
-dataset location is used to hillshade the <tt>elevation</tt> map:
-
-<div class="code"><pre>
-g.region raster=aspect -p
-d.shadedmap reliefmap=aspect drapemap=elevation
-</pre></div>
-
-In this next example, a shaded relief raster map is created in
-the Spearfish sample dataset and used to create a colorized hillshade
-raster map for later use:
-
-<div class="code"><pre>
-g.region raster=elevation.10m
-r.colors -e map=elevation.10m color=haxby
-r.shaded.relief elevation.10m
-
-d.shadedmap reliefmap=elevation.10m.shade drapemap=elevation.10m \
-   output=elevation.10m.shade.colorized
-
-r.colors -r map=elevation.10m
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="d.his.html">d.his</a>,
-<a href="g.pnmcomp.html">g.pnmcomp</a>,
-<a href="r.his.html">r.his</a>,
-<a href="r.slope.aspect.html">r.slope.aspect</a>,
-<a href="r.shaded.relief.html">r.shaded.relief</a><br>
-<a href="wxGUI.nviz.html">wxGUI 3D viewer (NVIZ)</a>
-</em>
-
-
-<h2>AUTHORS</h2>
-
-Unknown; updated to GRASS 5.7 by Michael Barton
-
-<p>
-<i>Last changed: $Date$</i>

+ 5 - 3
scripts/r.blend/r.blend.html

@@ -20,11 +20,13 @@ d.rgb blue=elev_shade_blend.b green=elev_shade_blend.g red=elev_shade_blend.r
 <h2>SEE ALSO</h2>
 
 <em>
-<a href="d.shadedmap.html">d.shadedmap</a>,
-<a href="g.region.html">g.region</a>,
+<a href="r.shade.html">r.shade</a>,
+<a href="r.his.html">r.his</a>,
 <a href="r.mapcalc.html">r.mapcalc</a>,
 <a href="r.colors.html">r.colors</a>,
-<a href="r.support.html">r.support</a>
+<a href="r.support.html">r.support</a>,
+<a href="d.shade.html">d.shade</a>,
+<a href="g.region.html">g.region</a>
 </em>
 
 

+ 7 - 0
scripts/r.shade/Makefile

@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.shade
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

+ 109 - 0
scripts/r.shade/r.shade.html

@@ -0,0 +1,109 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.shade</em> will drape a color raster map over a shaded relief map.
+In place of shaded relief, any raster map can be used including aspect or slope.
+The color raster map is usually an elevation raster map with colorful color
+table (as opposed to gray scale color table). However, any raster map can be
+used including categorical raster maps.
+The result is a raster map created from elevation and the shade raster.
+
+<p>
+Comparing to creating shaded relief as semi-transparent overlay on
+the color raster map, this module gives result with more saturated colors.
+
+<p>
+The input for this module can be created for example using
+<a href="r.slope.aspect.html">r.slope.aspect</a> or
+<a href="r.relief.html">r.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;
+<em>r.shade</em> is a frontend to that module with addition of
+brightness support similar to one provided by
+<em><a href="d.shade.html">d.shade</a></em>.
+However, note that the brightness is not implemenented in the same way as for
+<em><a href="d.shade.html">d.shade</a></em> and the results might
+be different.
+<em>r.shade</em> is using method described in <a href="r.his.html">r.his</a>
+manual page.
+
+
+<h2>EXAMPLES</h2>
+
+In this example, the <tt>aspect</tt> map in the North Carolina sample
+dataset location is used to hillshade the <tt>elevation</tt> map:
+
+<div class="code"><pre>
+g.region raster=aspect -p
+r.shade reliefmap=aspect drapemap=elevation output=elevation_aspect_shaded
+
+d.mon wx0
+d.rast elevation_aspect_shaded
+</pre></div>
+
+In this next example, a shaded relief raster map is created
+and used to create a colorized hillshade
+raster map for later use:
+
+<div class="code"><pre>
+g.region raster=elevation
+r.relief input=elevation output=elevation_shaded_relief
+
+r.shade reliefmap=elevation_shaded_relief drapemap=elevation \
+    output=elevation_relief_shaded
+
+d.mon wx1
+d.rast elevation_relief_shaded
+</pre></div>
+
+Interesting visualizations can be created using different color tables for
+elevation raster map, for example using <tt>haxby</tt> color table.
+
+<!--
+image generated using the example above
+display region: g.region -a n=227228 s=220895 w=631362 e=641170
+d.out.file rshade.png
+optipng -o5 rshade.png
+Note: The image is darker in the GNOME image viewer than the one in the map
+display. However, Firefox shows the same colors.
+-->
+<center>
+<img src="rshade.png" alt="Elevation with shaded relief (hillshade)">
+<p>
+Figure: A detail of raster created by applying shading effect of shaded relief
+(hillshade) to elevation raster map from North Carolina dataset elevation map
+</center>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.his.html">r.his</a>,
+<a href="d.his.html">d.his</a>,
+<a href="d.shade.html">d.shade</a>,
+<a href="g.pnmcomp.html">g.pnmcomp</a>,
+<a href="r.slope.aspect.html">r.slope.aspect</a>,
+<a href="r.relief.html">r.relief</a>
+</em>
+
+
+<h2>AUTHORS</h2>
+
+Hamish Bowman<br>
+Vaclav Petras, <a href="http://geospatial.ncsu.edu/osgeorel/">NCSU OSGeoREL</a><br>
+Inspired by <em><a href="d.shade.html">d.shade</a></em> and
+manual for <em><a href="r.his.html">r.his</a></em>.
+
+<p>
+<i>Last changed: $Date$</i>

+ 126 - 0
scripts/r.shade/r.shade.py

@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+#
+############################################################################
+#
+# MODULE:        r.shade
+# AUTHOR(S):     Hamish Bowman
+#                Vaclav Petras <wenzeslaus gmail com>
+#                Inspired by d.shade (formerly d.shadedmap)
+# PURPOSE:       Uses r.his to drape a color raster over a shaded relief map
+# COPYRIGHT:     (C) 2014 by Hamish Bowman, and 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: Drapes a color raster over an shaded relief or aspect map.
+#% keywords: raster
+#% keywords: elevation
+#% keywords: relief
+#% keywords: hillshade
+#% keywords: visualization
+#%end
+#%option G_OPT_R_INPUT
+#% key: reliefmap
+#% description: Name of shaded relief or aspect raster map
+#%end
+#%option G_OPT_R_INPUT
+#% key: drapemap
+#% label: Name of raster to drape over relief raster map
+#% description: Typically, this raster is elevation or other colorful raster
+#%end
+#%option G_OPT_R_OUTPUT
+#% description: Name of shaded raster map
+#%end
+#%option
+#% key: brighten
+#% type: integer
+#% description: Percent to brighten
+#% 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
+from grass.exceptions import CalledModuleError
+
+
+def remove(maps):
+    """Remove raster maps"""
+    gcore.run_command('g.remove', flags='f', quiet=True,
+                      type='rast', name=maps)
+
+
+def main():
+    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__rshade_%d' % os.getpid()
+        tmp_base = '%s_drape' % unique_name
+        tmp_r = tmp_base + '.r'
+        tmp_g = tmp_base + '.g'
+        tmp_b = tmp_base + '.b'
+
+        if brighten:
+            # steps taken from r.his manual page
+            # how much they are similar with d.shade/d.his is unknown
+            # perhaps even without brightness, there can be some differences
+            # comparing to d.shade
+            relief_map_tmp = '%s_relief' % unique_name
+            # convert [-99, -99] to [0.01, 1.99]
+            brighten = 1 + brighten / 100.
+            grast.mapcalc('{n} = {c} * #{o}'.format(
+                n=relief_map_tmp, o=relief_map, c=brighten))
+            gcore.run_command('r.colors', map=relief_map_tmp, color='grey255')
+            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, **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)
+        remove(to_remove)  # who knows if finally is called when exit
+    except CalledModuleError, error:
+        remove(to_remove)
+        # TODO: implement module name to CalledModuleError
+        gcore.fatal(_("Module %s failed. Check the above error messages.") % error.cmd)
+
+
+if __name__ == "__main__":
+    main()

BIN
scripts/r.shade/rshade.png