[GRASS-SVN] r66683 - grass-addons/grass7/raster/r.skyview
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Oct 30 12:29:49 PDT 2015
Author: wenzeslaus
Date: 2015-10-30 12:29:49 -0700 (Fri, 30 Oct 2015)
New Revision: 66683
Modified:
grass-addons/grass7/raster/r.skyview/r.skyview.py
Log:
r.skyview: add option to shade input or other maps with the output
This adds functionality which could be done by the user
manually afterwards but this gives a narrower set of choices
and adds convenience. (Similarly to r66628.)
Modified: grass-addons/grass7/raster/r.skyview/r.skyview.py
===================================================================
--- grass-addons/grass7/raster/r.skyview/r.skyview.py 2015-10-30 19:09:12 UTC (rev 66682)
+++ grass-addons/grass7/raster/r.skyview/r.skyview.py 2015-10-30 19:29:49 UTC (rev 66683)
@@ -5,6 +5,7 @@
# MODULE: r.skyview
#
# AUTHOR(S): Anna Petrasova (kratochanna gmail.com)
+# Vaclav Petras <wenzeslaus gmail com> (colorize addition)
#
# PURPOSE: Implementation of Sky-View Factor visualization technique
#
@@ -40,11 +41,51 @@
#% required: no
#%end
#%option
+#% key: color_source
+#% type: string
+#% label: Source raster for colorization
+#% description: Input and color_input are taken from input and color_input options respectively. The rest is computed using r.slope.aspect
+#% descriptions: input; use the raster from the input option;color_input;use the raster from the color_input option;slope;compute and use slope;aspect;compute and use aspect;dxy;compute and use second order partial derivative dxy
+#% multiple: no
+#% required: no
+#% options: input, color_input, slope, aspect, dxy
+#% answer: input
+#% guisection: Colorize
+#%end
+#%option G_OPT_R_INPUT
+#% key: color_input
+#% required: no
+#% description: Custom raster map to be used for colorization
+#% guisection: Colorize
+#%end
+#%option
+#% key: color_table
+#% type: string
+#% label: Color table for colorization raster (preset color table by default)
+#% description: If empty, the color table of the created raster is used (not used at all for input and color_input)
+#% multiple: no
+#% required: no
+#% options: reds, blues, greens, oranges, sepia, aspectcolr
+#% guisection: Colorize
+#%end
+#%option G_OPT_R_OUTPUT
+#% key: colorized_output
+#% required: no
+#% description: Colorized sky-view factor
+#% guisection: Colorize
+#%end
+#%option
#% key: basename
#% type: string
#% multiple: no
#% description: Set the basename for the intermediate maps
#%end
+#%flag
+#% key: n
+#% label: Invert color table for colorization raster
+#% description: Ignored for input and color_input
+#% guisection: Colorize
+#%end
import sys
@@ -57,6 +98,7 @@
from grass.pygrass.messages import get_msgr
+# TODO: also used for r.slope.aspect result
TMP_NAME = 'tmp_horizon_' + str(os.getpid())
CLEANUP = True
@@ -75,6 +117,28 @@
if options['basename']:
TMP_NAME = options['basename']
CLEANUP = False
+ colorized_output = options['colorized_output']
+ colorize_color = options['color_table']
+ if colorized_output:
+ color_raster_tmp = TMP_NAME + "_color_raster"
+ else:
+ color_raster_tmp = None
+ color_raster_type = options['color_source']
+ color_input = options['color_input']
+ if color_raster_type == 'color_input' and not color_input:
+ gcore.fatal(_("Provide raster name in color_input option"))
+ if color_raster_type != 'color_input' and color_input:
+ gcore.fatal(_("The option color_input is not needed"
+ " when not using it as source for color"))
+ # this would be needed only when no value would allowed
+ if not color_raster_type and color_input:
+ color_raster_type = 'color_input' # enable for convenience
+ if color_raster_type == 'aspect' \
+ and colorize_color \
+ and colorize_color not in ['default', 'aspectcolr']:
+ gcore.warning(_("Using possibly inappropriate color table <{}>"
+ " for aspect".format(colorize_color)))
+
horizon_step = 360. / n_dir
msgr = get_msgr()
@@ -89,6 +153,8 @@
else:
msgr.warning(_("The following maps will be overwritten: {names}"
).format(names=','.join(old_maps)))
+ if not gcore.overwrite() and color_raster_tmp:
+ check_map_name(color_raster_tmp)
try:
gcore.run_command('r.horizon', elevation=elev, step=horizon_step,
output=TMP_NAME, flags='d')
@@ -106,6 +172,31 @@
msgr.fatal(_("r.horizon failed to compute horizon elevation "
"angle maps. Please report this problem to developers."))
return 1
+ if colorized_output:
+ if color_raster_type == 'slope':
+ gcore.run_command('r.slope.aspect', elevation=elev,
+ slope=color_raster_tmp)
+ elif color_raster_type == 'aspect':
+ gcore.run_command('r.slope.aspect', elevation=elev,
+ aspect=color_raster_tmp)
+ elif color_raster_type == 'dxy':
+ gcore.run_command('r.slope.aspect', elevation=elev,
+ dxy=color_raster_tmp)
+ elif color_raster_type == 'color_input':
+ color_raster_tmp = color_input
+ else:
+ color_raster_tmp = elev
+ # don't modify user's color table for inputs
+ if colorize_color \
+ and color_raster_type not in ['input', 'color_input']:
+ rcolors_flags = ''
+ if flags['n']:
+ rcolors_flags += 'n'
+ gcore.run_command('r.colors', map=color_raster_tmp,
+ color=colorize_color,
+ flags=rcolors_flags)
+ gcore.run_command('r.shade', shade=output, color=color_raster_tmp,
+ output=colorized_output)
return 0
@@ -114,6 +205,15 @@
pattern=TMP_NAME + "*")[gcore.gisenv()['MAPSET']]
+def check_map_name(name):
+ # cell means any raster in this context
+ # mapset needs to retrieved in very call, ok for here
+ if gcore.find_file(name, element='cell',
+ mapset=gcore.gisenv()['MAPSET'])['file']:
+ gcore.fatal(_("Raster map <%s> already exists. "
+ "Remove the existing map or allow overwrite.") % name)
+
+
if __name__ == "__main__":
options, flags = gcore.parser()
atexit.register(cleanup)
More information about the grass-commit
mailing list