Skip to content
Permalink
Browse files

Port aspect algorithm to new API

  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent 2f28736 commit dfb687bf64a49ccd8c5fddd04fd644d78785ebd9
@@ -30,12 +30,16 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsAspectFilter

from processing.algs.qgis import QgisAlgorithm
from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterOutput,
QgsProcessingOutputRasterLayer)
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]

@@ -54,12 +58,14 @@ def group(self):

def __init__(self):
super().__init__()
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.addOutput(OutputRaster(self.OUTPUT_LAYER,
self.tr('Aspect')))

self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT_LAYER,
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 1, 999999.99))
self.addParameter(QgsProcessingParameterRasterOutput(self.OUTPUT_LAYER, self.tr('Aspect')))
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT_LAYER, self.tr('Aspect')))

def name(self):
return 'aspect'
@@ -68,12 +74,15 @@ def displayName(self):
return self.tr('Aspect')

def processAlgorithm(self, parameters, context, feedback):
inputFile = self.getParameterValue(self.INPUT_LAYER)
zFactor = self.getParameterValue(self.Z_FACTOR)
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT_LAYER, context))
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)

outputFile = self.parameterAsRasterOutputLayer(parameters, self.OUTPUT_LAYER, context)

outputFormat = raster.formatShortNameFromFileName(outputFile)

aspect = QgsAspectFilter(inputFile, outputFile, outputFormat)
aspect.setZFactor(zFactor)
aspect.processRaster(None)

return {self.OUTPUT_LAYER: outputFile}
@@ -1035,18 +1035,18 @@ tests:
# name: expected/points_in_polys.gml
# type: vector
#
# - algorithm: qgis:aspect
# name: Aspect from QGIS analysis library
# params:
# INPUT_LAYER:
# name: dem.tif
# type: raster
# Z_FACTOR: 1.0
# results:
# OUTPUT_LAYER:
# hash: 762865ee485a6736d188402aa10e6fd38a812a9e45a7dd2d4885a63a
# type: rasterhash
#
- algorithm: qgis:aspect
name: Aspect from QGIS analysis library
params:
INPUT_LAYER:
name: dem.tif
type: raster
Z_FACTOR: 1.0
results:
OUTPUT_LAYER:
hash: 762865ee485a6736d188402aa10e6fd38a812a9e45a7dd2d4885a63a
type: rasterhash

# - algorithm: qgis:slope
# name: Slope from QGIS analysis library
# params:

0 comments on commit dfb687b

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