Skip to content

Commit dfb687b

Browse files
committed
Port aspect algorithm to new API
1 parent 2f28736 commit dfb687b

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

python/plugins/processing/algs/qgis/Aspect.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@
3030
from qgis.PyQt.QtGui import QIcon
3131

3232
from qgis.analysis import QgsAspectFilter
33-
34-
from processing.algs.qgis import QgisAlgorithm
33+
from qgis.core import (QgsProcessingParameterRasterLayer,
34+
QgsProcessingParameterNumber,
35+
QgsProcessingParameterRasterOutput,
36+
QgsProcessingOutputRasterLayer)
37+
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
3538
from processing.core.parameters import ParameterRaster
3639
from processing.core.parameters import ParameterNumber
3740
from processing.core.outputs import OutputRaster
3841
from processing.tools import raster
42+
from processing.tools.dataobjects import exportRasterLayer
3943

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

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

5559
def __init__(self):
5660
super().__init__()
57-
self.addParameter(ParameterRaster(self.INPUT_LAYER,
58-
self.tr('Elevation layer')))
59-
self.addParameter(ParameterNumber(self.Z_FACTOR,
60-
self.tr('Z factor'), 1.0, 999999.99, 1.0))
61-
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
62-
self.tr('Aspect')))
61+
62+
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT_LAYER,
63+
self.tr('Elevation layer')))
64+
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
65+
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
66+
1, False, 1, 999999.99))
67+
self.addParameter(QgsProcessingParameterRasterOutput(self.OUTPUT_LAYER, self.tr('Aspect')))
68+
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT_LAYER, self.tr('Aspect')))
6369

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

7076
def processAlgorithm(self, parameters, context, feedback):
71-
inputFile = self.getParameterValue(self.INPUT_LAYER)
72-
zFactor = self.getParameterValue(self.Z_FACTOR)
73-
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
77+
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT_LAYER, context))
78+
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
79+
80+
outputFile = self.parameterAsRasterOutputLayer(parameters, self.OUTPUT_LAYER, context)
7481

7582
outputFormat = raster.formatShortNameFromFileName(outputFile)
7683

7784
aspect = QgsAspectFilter(inputFile, outputFile, outputFormat)
7885
aspect.setZFactor(zFactor)
7986
aspect.processRaster(None)
87+
88+
return {self.OUTPUT_LAYER: outputFile}

python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1035,18 +1035,18 @@ tests:
10351035
# name: expected/points_in_polys.gml
10361036
# type: vector
10371037
#
1038-
# - algorithm: qgis:aspect
1039-
# name: Aspect from QGIS analysis library
1040-
# params:
1041-
# INPUT_LAYER:
1042-
# name: dem.tif
1043-
# type: raster
1044-
# Z_FACTOR: 1.0
1045-
# results:
1046-
# OUTPUT_LAYER:
1047-
# hash: 762865ee485a6736d188402aa10e6fd38a812a9e45a7dd2d4885a63a
1048-
# type: rasterhash
1049-
#
1038+
- algorithm: qgis:aspect
1039+
name: Aspect from QGIS analysis library
1040+
params:
1041+
INPUT_LAYER:
1042+
name: dem.tif
1043+
type: raster
1044+
Z_FACTOR: 1.0
1045+
results:
1046+
OUTPUT_LAYER:
1047+
hash: 762865ee485a6736d188402aa10e6fd38a812a9e45a7dd2d4885a63a
1048+
type: rasterhash
1049+
10501050
# - algorithm: qgis:slope
10511051
# name: Slope from QGIS analysis library
10521052
# params:

0 commit comments

Comments
 (0)