From 15902aa2fa229dabbbf68c649eb62d751fcac1cb Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 6 Oct 2016 19:37:11 +0300 Subject: [PATCH] [processing] expose Hillshade from Raster terrain analysis plugin in toolbox --- .../plugins/processing/algs/qgis/Hillshade.py | 72 +++++++++++++++++++ .../algs/qgis/QGISAlgorithmProvider.py | 3 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 python/plugins/processing/algs/qgis/Hillshade.py diff --git a/python/plugins/processing/algs/qgis/Hillshade.py b/python/plugins/processing/algs/qgis/Hillshade.py new file mode 100644 index 000000000000..b9367e781b37 --- /dev/null +++ b/python/plugins/processing/algs/qgis/Hillshade.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + Hillshade.py + --------------------- + Date : October 2016 + Copyright : (C) 2016 by Alexander Bruy + Email : alexander dot bruy at gmail dot com +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" +from builtins import str + +__author__ = 'Alexander Bruy' +__date__ = 'October 2016' +__copyright__ = '(C) 2016, Alexander Bruy' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from qgis.analysis import QgsHillshadeFilter + +from processing.core.GeoAlgorithm import GeoAlgorithm +from processing.core.parameters import ParameterRaster +from processing.core.parameters import ParameterNumber +from processing.core.outputs import OutputRaster +from processing.tools import raster + + +class Hillshade(GeoAlgorithm): + + INPUT_LAYER = 'INPUT_LAYER' + Z_FACTOR = 'Z_FACTOR' + AZIMUTH = 'AZIMUTH' + V_ANGLE = 'V_ANGLE' + OUTPUT_LAYER = 'OUTPUT_LAYER' + + def defineCharacteristics(self): + self.name, self.i18n_name = self.trAlgorithm('Hillshade') + self.group, self.i18n_group = self.trAlgorithm('Raster terrain analysis') + + self.addParameter(ParameterRaster(self.INPUT_LAYER, + self.tr('Elevation layer'))) + self.addParameter(ParameterNumber(self.Z_FACTOR, + self.tr('Z factor'), 1.0, 999999.99, 1.0)) + self.addParameter(ParameterNumber(self.AZIMUTH, + self.tr('Azimuth (horizontal angle)'), 0.00, 360.00, 300.00)) + self.addParameter(ParameterNumber(self.V_ANGLE, + self.tr('Vertical angle'), 1.00, 90.00, 40.00)) + self.addOutput(OutputRaster(self.OUTPUT_LAYER, + self.tr('Hillshade'))) + + def processAlgorithm(self, progress): + inputFile = self.getParameterValue(self.INPUT_LAYER) + zFactor = self.getParameterValue(self.Z_FACTOR) + azimuth = self.getParameterValue(self.AZIMUTH) + vAngle = self.getParameterValue(self.V_ANGLE) + outputFile = self.getOutputValue(self.OUTPUT_LAYER) + + outputFormat = raster.formatShortNameFromFileName(outputFile) + + hillshade = QgsHillshadeFilter(inputFile, outputFile, outputFormat, azimuth, vAngle) + hillshade.setZFactor(zFactor) + hillshade.processRaster(None) diff --git a/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py b/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py index 1929146611cc..fc1bb67b4b23 100644 --- a/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py +++ b/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py @@ -161,6 +161,7 @@ from .Aspect import Aspect from .Slope import Slope from .Ruggedness import Ruggedness +from .Hillshade import Hillshade pluginPath = os.path.normpath(os.path.join( os.path.split(os.path.dirname(__file__))[0], os.pardir)) @@ -217,7 +218,7 @@ def __init__(self): BoundingBox(), Boundary(), PointOnSurface(), OffsetLine(), PolygonCentroids(), Translate(), SingleSidedBuffer(), PointsAlongGeometry(), - Aspect(), Slope(), Ruggedness(), + Aspect(), Slope(), Ruggedness(), Hillshade(), ] if hasMatplotlib: