Skip to content
Permalink
Browse files

[processing] restore Hillshade algorithm

  • Loading branch information
alexbruy committed Jul 15, 2017
1 parent f4bba54 commit f3f9e544ab75df168964d215c6dfc0ee8303ba24
@@ -30,23 +30,23 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsHillshadeFilter

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputRaster
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]


class Hillshade(QgisAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
INPUT = 'INPUT'
Z_FACTOR = 'Z_FACTOR'
AZIMUTH = 'AZIMUTH'
V_ANGLE = 'V_ANGLE'
OUTPUT_LAYER = 'OUTPUT_LAYER'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'dem.png'))
@@ -58,16 +58,18 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
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')))
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 1, 999999.99))
self.addParameter(QgsProcessingParameterNumber(self.AZIMUTH,
self.tr('Azimuth (horizontal angle)'), QgsProcessingParameterNumber.Double,
300, False, 0, 360))
self.addParameter(QgsProcessingParameterNumber(self.V_ANGLE,
self.tr('Vertical angle'), QgsProcessingParameterNumber.Double,
40, False, 1, 90))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Hillshade')))

def name(self):
return 'hillshade'
@@ -76,14 +78,17 @@ def displayName(self):
return self.tr('Hillshade')

def processAlgorithm(self, parameters, context, feedback):
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)
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context))
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
azimuth = self.parameterAsDouble(parameters, self.AZIMUTH, context)
vAngle = self.parameterAsDouble(parameters, self.V_ANGLE, context)

outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

outputFormat = raster.formatShortNameFromFileName(outputFile)

hillshade = QgsHillshadeFilter(inputFile, outputFile, outputFormat, azimuth, vAngle)
hillshade.setZFactor(zFactor)
hillshade.processRaster(None)
hillshade.processRaster(feedback)

return {self.OUTPUT: outputFile}
@@ -60,6 +60,7 @@
from .FixGeometry import FixGeometry
from .GridPolygon import GridPolygon
from .Heatmap import Heatmap
from .Hillshade import Hillshade
from .ImportIntoPostGIS import ImportIntoPostGIS
from .ImportIntoSpatialite import ImportIntoSpatialite
from .Intersection import Intersection
@@ -148,7 +149,6 @@
# from .Translate import Translate
# from .SingleSidedBuffer import SingleSidedBuffer
# from .PointsAlongGeometry import PointsAlongGeometry
# from .Hillshade import Hillshade
# from .Relief import Relief
# from .IdwInterpolation import IdwInterpolation
# from .TinInterpolation import TinInterpolation
@@ -254,6 +254,7 @@ def getAlgs(self):
FixGeometry(),
GridPolygon(),
Heatmap(),
Hillshade(),
ImportIntoPostGIS(),
ImportIntoSpatialite(),
Intersection(),
@@ -1068,20 +1068,20 @@ tests:
hash: ff630246e8dc19c7217d81261c6b64f965c17fa04d3e41d7979c1f1e
type: rasterhash

# - algorithm: qgis:hillshade
# name: Hillshade from QGIS analysis library
# params:
# AZIMUTH: 300.0
# INPUT_LAYER:
# name: dem.tif
# type: raster
# V_ANGLE: 40.0
# Z_FACTOR: 1.0
# results:
# OUTPUT_LAYER:
# hash: 58365b3715b925d6286e7f082ebd9c2a20f09fa1c922176d3f238002
# type: rasterhash
#
- algorithm: qgis:hillshade
name: Hillshade from QGIS analysis library
params:
AZIMUTH: 300.0
INPUT_LAYER:
name: dem.tif
type: raster
V_ANGLE: 40.0
Z_FACTOR: 1.0
results:
OUTPUT_LAYER:
hash: 58365b3715b925d6286e7f082ebd9c2a20f09fa1c922176d3f238002
type: rasterhash

# - algorithm: qgis:relief
# name: Relief (automatic colors generation)
# params:

0 comments on commit f3f9e54

Please sign in to comment.
You can’t perform that action at this time.