Skip to content

Commit 15902aa

Browse files
committedOct 11, 2016
[processing] expose Hillshade from Raster terrain analysis plugin in toolbox
1 parent 2c2ff64 commit 15902aa

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed
 
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
Hillshade.py
6+
---------------------
7+
Date : October 2016
8+
Copyright : (C) 2016 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
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+
from builtins import str
20+
21+
__author__ = 'Alexander Bruy'
22+
__date__ = 'October 2016'
23+
__copyright__ = '(C) 2016, Alexander Bruy'
24+
25+
# This will get replaced with a git SHA1 when you do a git archive
26+
27+
__revision__ = '$Format:%H$'
28+
29+
from qgis.analysis import QgsHillshadeFilter
30+
31+
from processing.core.GeoAlgorithm import GeoAlgorithm
32+
from processing.core.parameters import ParameterRaster
33+
from processing.core.parameters import ParameterNumber
34+
from processing.core.outputs import OutputRaster
35+
from processing.tools import raster
36+
37+
38+
class Hillshade(GeoAlgorithm):
39+
40+
INPUT_LAYER = 'INPUT_LAYER'
41+
Z_FACTOR = 'Z_FACTOR'
42+
AZIMUTH = 'AZIMUTH'
43+
V_ANGLE = 'V_ANGLE'
44+
OUTPUT_LAYER = 'OUTPUT_LAYER'
45+
46+
def defineCharacteristics(self):
47+
self.name, self.i18n_name = self.trAlgorithm('Hillshade')
48+
self.group, self.i18n_group = self.trAlgorithm('Raster terrain analysis')
49+
50+
self.addParameter(ParameterRaster(self.INPUT_LAYER,
51+
self.tr('Elevation layer')))
52+
self.addParameter(ParameterNumber(self.Z_FACTOR,
53+
self.tr('Z factor'), 1.0, 999999.99, 1.0))
54+
self.addParameter(ParameterNumber(self.AZIMUTH,
55+
self.tr('Azimuth (horizontal angle)'), 0.00, 360.00, 300.00))
56+
self.addParameter(ParameterNumber(self.V_ANGLE,
57+
self.tr('Vertical angle'), 1.00, 90.00, 40.00))
58+
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
59+
self.tr('Hillshade')))
60+
61+
def processAlgorithm(self, progress):
62+
inputFile = self.getParameterValue(self.INPUT_LAYER)
63+
zFactor = self.getParameterValue(self.Z_FACTOR)
64+
azimuth = self.getParameterValue(self.AZIMUTH)
65+
vAngle = self.getParameterValue(self.V_ANGLE)
66+
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
67+
68+
outputFormat = raster.formatShortNameFromFileName(outputFile)
69+
70+
hillshade = QgsHillshadeFilter(inputFile, outputFile, outputFormat, azimuth, vAngle)
71+
hillshade.setZFactor(zFactor)
72+
hillshade.processRaster(None)

‎python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
from .Aspect import Aspect
162162
from .Slope import Slope
163163
from .Ruggedness import Ruggedness
164+
from .Hillshade import Hillshade
164165

165166
pluginPath = os.path.normpath(os.path.join(
166167
os.path.split(os.path.dirname(__file__))[0], os.pardir))
@@ -217,7 +218,7 @@ def __init__(self):
217218
BoundingBox(), Boundary(), PointOnSurface(),
218219
OffsetLine(), PolygonCentroids(), Translate(),
219220
SingleSidedBuffer(), PointsAlongGeometry(),
220-
Aspect(), Slope(), Ruggedness(),
221+
Aspect(), Slope(), Ruggedness(), Hillshade(),
221222
]
222223

223224
if hasMatplotlib:

0 commit comments

Comments
 (0)