Skip to content

Commit 717687b

Browse files
author
Médéric RIBREUX
committed
Add r.shade algorithm
1 parent 4863504 commit 717687b

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
r.shade
2+
Drapes a color raster over an shaded relief or aspect map.
3+
Raster (r.*)
4+
ParameterRaster|shade|Name of shaded relief or aspect raster map|False
5+
ParameterRaster|color|Name of raster to drape over relief raster map|False
6+
ParameterNumber|brighten|Percent to brighten|-99|99|0|True
7+
ParameterString|bgcolor|Color to use instead of NULL values. Either a standard color name, R:G:B triplet, or "none"|None|False|True
8+
*ParameterBoolean|-c|Use colors from color tables for NULL values|False
9+
OutputRaster|output|Shaded
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
r_shade.py
6+
----------
7+
Date : February 2016
8+
Copyright : (C) 2016 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'February 2016'
22+
__copyright__ = '(C) 2016, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
29+
def checkParameterValuesBeforeExecuting(alg):
30+
""" Verify if we have the right parameters """
31+
if alg.getParameterValue('brighten') and alg.getParameterValue('bgcolor'):
32+
return alg.tr("You need to set either a brighten percentage or a NULL color !")
33+
return None
34+
35+
36+
def processInputs(alg):
37+
# We need to import all the bands and color tables of the input rasters
38+
shade = alg.getParameterValue('shade')
39+
color = alg.getParameterValue('color')
40+
if color in alg.exportedLayers.keys():
41+
return
42+
43+
for raster, method in (shade, 'r.external'), (color, 'r.in.gdal'):
44+
alg.setSessionProjectionFromLayer(raster, alg.commands)
45+
46+
destFilename = alg.getTempFilename()
47+
alg.exportedLayers[raster] = destFilename
48+
command = '{} input={} output={} --overwrite -o'.format(method, raster, destFilename)
49+
alg.commands.append(command)
50+
51+
alg.setSessionProjectionFromProject(alg.commands)
52+
53+
region = unicode(alg.getParameterValue(alg.GRASS_REGION_EXTENT_PARAMETER))
54+
regionCoords = region.split(',')
55+
command = 'g.region'
56+
command += ' -a'
57+
command += ' n=' + unicode(regionCoords[3])
58+
command += ' s=' + unicode(regionCoords[2])
59+
command += ' e=' + unicode(regionCoords[1])
60+
command += ' w=' + unicode(regionCoords[0])
61+
cellsize = alg.getParameterValue(alg.GRASS_REGION_CELLSIZE_PARAMETER)
62+
if cellsize:
63+
command += ' res=' + unicode(cellsize)
64+
else:
65+
command += ' res=' + unicode(alg.getDefaultCellsize())
66+
alignToResolution = alg.getParameterValue(alg.GRASS_REGION_ALIGN_TO_RESOLUTION)
67+
if alignToResolution:
68+
command += ' -a'
69+
alg.commands.append(command)
70+
71+
72+
def processOutputs(alg):
73+
# Keep color table ?
74+
output = alg.getOutputValue(u'output')
75+
command = u"r.out.gdal -t createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format(
76+
alg.exportedLayers[output],
77+
output
78+
)
79+
alg.commands.append(command)
80+
alg.outputCommands.append(command)

0 commit comments

Comments
 (0)