[GRASS-SVN] r62845 - in grass/trunk/scripts: . d.shadedmap r.shadedmap

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 20 20:00:29 PST 2014


Author: wenzeslaus
Date: 2014-11-20 20:00:29 -0800 (Thu, 20 Nov 2014)
New Revision: 62845

Added:
   grass/trunk/scripts/d.shadedmap/dshadedmap.png
   grass/trunk/scripts/r.shadedmap/
   grass/trunk/scripts/r.shadedmap/r.shadedmap.html
   grass/trunk/scripts/r.shadedmap/r.shadedmap.py
   grass/trunk/scripts/r.shadedmap/rshadedmap.png
Removed:
   grass/trunk/scripts/r.shadedmap/d.shadedmap.html
   grass/trunk/scripts/r.shadedmap/d.shadedmap.py
Modified:
   grass/trunk/scripts/Makefile
   grass/trunk/scripts/d.shadedmap/d.shadedmap.html
   grass/trunk/scripts/d.shadedmap/d.shadedmap.py
   grass/trunk/scripts/r.shadedmap/Makefile
Log:
d.shadedmap: split into two modules d.shadedmap for display and r.shadedmap for creating raster

 * the raster creation functionality was anyway not sharing any code with the display part in the original d.shadedmap 
 * similar things are parameters and manual, so there is now some duplication in this
 * thanks to r.shadedmap, GRASS shading is available to QGIS and others
 * in wxGUI one can create the raster in usual way (before: pressing OK or Apply in d command dialog with no overwrite support)
 * adds also brighten functionality for r.shadedmap implemented according to r.his manual (probably not perfect) 
 * changing examples to NC and adding images (different image for each module)


Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile	2014-11-21 02:33:51 UTC (rev 62844)
+++ grass/trunk/scripts/Makefile	2014-11-21 04:00:29 UTC (rev 62845)
@@ -43,6 +43,7 @@
 	r.plane \
 	r.reclass.area \
 	r.rgb \
+	r.shadedmap \
 	r.tileset \
 	r.unpack \
 	r3.in.xyz \

Modified: grass/trunk/scripts/d.shadedmap/d.shadedmap.html
===================================================================
--- grass/trunk/scripts/d.shadedmap/d.shadedmap.html	2014-11-21 02:33:51 UTC (rev 62844)
+++ grass/trunk/scripts/d.shadedmap/d.shadedmap.html	2014-11-21 04:00:29 UTC (rev 62845)
@@ -1,17 +1,29 @@
 <h2>DESCRIPTION</h2>
 
 <em>d.shadedmap</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.shaded.relief.html">r.shaded.relief</a><br>.
+
+
 <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. -->
+Refer to the <em><a href="d.his.html">d.his</a></em> help page for more details;
+<em>d.shadedmap</em> is simply a frontend to that module.
 
+
 <h2>EXAMPLES</h2>
 
 In this example, the <tt>aspect</tt> map in the North Carolina sample
@@ -19,31 +31,50 @@
 
 <div class="code"><pre>
 g.region rast=aspect -p
+d.mon wx0
 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:
+<!--
+image generated using the example above
+display region: g.region -a n=227228 s=220895 w=631362 e=641170
+d.out.file dshadedmap.png
+optipng -o5 dshadedmap.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 rast=elevation.10m
-r.colors -e map=elevation.10m color=haxby
-r.shaded.relief elevation.10m
+g.region rast=elevation
+r.shaded.relief input=elevation output=elevation_shaded_relief
 
-d.shadedmap reliefmap=elevation.10m.shade drapemap=elevation.10m \
-   output=elevation.10m.shade.colorized
-
-r.colors -r map=elevation.10m
+d.mon wx1
+d.shadedmap 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.his.html">r.his</a>,
+<a href="r.shadedmap.html">r.shadedmap</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>

Modified: grass/trunk/scripts/d.shadedmap/d.shadedmap.py
===================================================================
--- grass/trunk/scripts/d.shadedmap/d.shadedmap.py	2014-11-21 02:33:51 UTC (rev 62844)
+++ grass/trunk/scripts/d.shadedmap/d.shadedmap.py	2014-11-21 04:00:29 UTC (rev 62845)
@@ -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,47 +38,25 @@
 #% 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()
+
     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', flags = 'f', quiet = True, 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
+        gcore.fatal(_("Module %s failed. Check the above error messages.") % 'd.his')
 
-    sys.exit(ret)
 
-
 if __name__ == "__main__":
-    options, flags = grass.parser()
     main()

Added: grass/trunk/scripts/d.shadedmap/dshadedmap.png
===================================================================
(Binary files differ)


Property changes on: grass/trunk/scripts/d.shadedmap/dshadedmap.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Modified: grass/trunk/scripts/r.shadedmap/Makefile
===================================================================
--- grass/trunk/scripts/d.shadedmap/Makefile	2014-11-18 03:24:44 UTC (rev 62791)
+++ grass/trunk/scripts/r.shadedmap/Makefile	2014-11-21 04:00:29 UTC (rev 62845)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = d.shadedmap
+PGM = r.shadedmap
 
 include $(MODULE_TOPDIR)/include/Make/Script.make
 

Deleted: grass/trunk/scripts/r.shadedmap/d.shadedmap.html
===================================================================
--- grass/trunk/scripts/d.shadedmap/d.shadedmap.html	2014-11-18 03:24:44 UTC (rev 62791)
+++ grass/trunk/scripts/r.shadedmap/d.shadedmap.html	2014-11-21 04:00:29 UTC (rev 62845)
@@ -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 rast=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 rast=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>

Deleted: grass/trunk/scripts/r.shadedmap/d.shadedmap.py
===================================================================
--- grass/trunk/scripts/d.shadedmap/d.shadedmap.py	2014-11-18 03:24:44 UTC (rev 62791)
+++ grass/trunk/scripts/r.shadedmap/d.shadedmap.py	2014-11-21 04:00:29 UTC (rev 62845)
@@ -1,80 +0,0 @@
-#!/usr/bin/env python
-#
-############################################################################
-#
-# MODULE:        d.shadedmap
-# 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
-# COPYRIGHT:     (C) 2004-2013 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: Drapes a color raster over a shaded relief map.
-#% keywords: display
-#% keywords: elevation
-#%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
-#% description: Name of raster to drape over relief raster map
-#%end
-#%option
-#% key: brighten
-#% type: integer
-#% description: Percent to brighten
-#% 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.exceptions import CalledModuleError
-
-
-def main():
-    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', flags = 'f', quiet = True, 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,
-                          brighten=brighten)
-    except CalledModuleError:
-        ret = 1
-
-    sys.exit(ret)
-
-
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    main()

Copied: grass/trunk/scripts/r.shadedmap/r.shadedmap.html (from rev 62791, grass/trunk/scripts/d.shadedmap/d.shadedmap.html)
===================================================================
--- grass/trunk/scripts/r.shadedmap/r.shadedmap.html	                        (rev 0)
+++ grass/trunk/scripts/r.shadedmap/r.shadedmap.html	2014-11-21 04:00:29 UTC (rev 62845)
@@ -0,0 +1,100 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.shadedmap</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.shaded.relief.html">r.shaded.relief</a><br>.
+
+
+<h2>NOTES</h2>
+
+Refer to the <a href="r.his.html">r.his</a> help page for more details;
+<em>r.shadedmap</em> is a frontend to that module with addition of
+brightness support similar to one provided by
+<em><a href="d.shadedmap.html">d.shadedmap</a></em>.
+However, note that the brightness is not implemenented in the same way as for
+<em><a href="d.shadedmap.html">d.shadedmap</a></em> and the results might
+be different.
+<em>r.shadedmap</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 rast=aspect -p
+r.shadedmap 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 rast=elevation
+r.shaded.relief input=elevation output=elevation_shaded_relief
+
+r.shadedmap 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 rshadedmap.png
+optipng -o5 rshadedmap.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="rshadedmap.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.shadedmap.html">d.shadedmap</a>,
+<a href="g.pnmcomp.html">g.pnmcomp</a>,
+<a href="r.slope.aspect.html">r.slope.aspect</a>,
+<a href="r.shaded.relief.html">r.shaded.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.shadedmap.html">d.shadedmap</a></em> and
+manual for <em><a href="r.his.html">r.his</a></em>.
+
+<p>
+<i>Last changed: $Date$</i>

Copied: grass/trunk/scripts/r.shadedmap/r.shadedmap.py (from rev 62791, grass/trunk/scripts/d.shadedmap/d.shadedmap.py)
===================================================================
--- grass/trunk/scripts/r.shadedmap/r.shadedmap.py	                        (rev 0)
+++ grass/trunk/scripts/r.shadedmap/r.shadedmap.py	2014-11-21 04:00:29 UTC (rev 62845)
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+#
+############################################################################
+#
+# MODULE:        r.shadedmap
+# AUTHOR(S):     Hamish Bowman
+#                Vaclav Petras <wenzeslaus gmail com>
+#                Inspired by 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
+
+
+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, unused = gcore.parser()
+
+    drape_map = options['drapemap']
+    relief_map = options['reliefmap']
+    brighten = int(options['brighten'])
+    output_map = options['output']
+
+    to_remove = []
+    try:
+        unique_name = 'tmp__rshadedmap_%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.shadedmap/d.his is unknown
+            # perhaps even without brightness, there can be some differences
+            # comparing to d.shadedmap
+            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)
+        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.args)
+
+
+if __name__ == "__main__":
+    main()

Added: grass/trunk/scripts/r.shadedmap/rshadedmap.png
===================================================================
(Binary files differ)


Property changes on: grass/trunk/scripts/r.shadedmap/rshadedmap.png
___________________________________________________________________
Added: svn:mime-type
   + image/png



More information about the grass-commit mailing list