Skip to content

Commit

Permalink
Port aspect algorithm to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent 2f28736 commit dfb687b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
31 changes: 20 additions & 11 deletions python/plugins/processing/algs/qgis/Aspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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'
Expand All @@ -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}
24 changes: 12 additions & 12 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit dfb687b

Please sign in to comment.