|
| 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) |
0 commit comments