Skip to content

Commit 05b4cc2

Browse files
committed
[processing] restore Slope algorithm
1 parent 5f5fc58 commit 05b4cc2

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
from .SelectByAttribute import SelectByAttribute
7777
from .SelectByExpression import SelectByExpression
7878
from .SimplifyGeometries import SimplifyGeometries
79+
from .Slope import Slope
7980
from .Smooth import Smooth
8081
from .SnapGeometries import SnapGeometriesToLayer
8182
from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
@@ -146,7 +147,6 @@
146147
# from .Translate import Translate
147148
# from .SingleSidedBuffer import SingleSidedBuffer
148149
# from .PointsAlongGeometry import PointsAlongGeometry
149-
# from .Slope import Slope
150150
# from .Ruggedness import Ruggedness
151151
# from .Hillshade import Hillshade
152152
# from .Relief import Relief
@@ -270,6 +270,7 @@ def getAlgs(self):
270270
SelectByAttribute(),
271271
SelectByExpression(),
272272
SimplifyGeometries(),
273+
Slope(),
273274
Smooth(),
274275
SnapGeometriesToLayer(),
275276
SpatialiteExecuteSQL(),

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@
3030
from qgis.PyQt.QtGui import QIcon
3131

3232
from qgis.analysis import QgsSlopeFilter
33-
33+
from qgis.core import (QgsProcessingParameterRasterLayer,
34+
QgsProcessingParameterNumber,
35+
QgsProcessingParameterRasterDestination)
3436
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
35-
from processing.core.parameters import ParameterRaster
36-
from processing.core.parameters import ParameterNumber
37-
from processing.core.outputs import OutputRaster
3837
from processing.tools import raster
38+
from processing.tools.dataobjects import exportRasterLayer
39+
3940

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

4243

4344
class Slope(QgisAlgorithm):
4445

45-
INPUT_LAYER = 'INPUT_LAYER'
46+
INPUT = 'INPUT'
4647
Z_FACTOR = 'Z_FACTOR'
47-
OUTPUT_LAYER = 'OUTPUT_LAYER'
48+
OUTPUT = 'OUTPUT'
4849

4950
def icon(self):
5051
return QIcon(os.path.join(pluginPath, 'images', 'dem.png'))
@@ -56,12 +57,12 @@ def __init__(self):
5657
super().__init__()
5758

5859
def initAlgorithm(self, config=None):
59-
self.addParameter(ParameterRaster(self.INPUT_LAYER,
60-
self.tr('Elevation layer')))
61-
self.addParameter(ParameterNumber(self.Z_FACTOR,
62-
self.tr('Z factor'), 1.0, 999999.99, 1.0))
63-
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
64-
self.tr('Slope')))
60+
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
61+
self.tr('Elevation layer')))
62+
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
63+
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
64+
1, False, 1, 999999.99))
65+
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Slope')))
6566

6667
def name(self):
6768
return 'slope'
@@ -70,12 +71,15 @@ def displayName(self):
7071
return self.tr('Slope')
7172

7273
def processAlgorithm(self, parameters, context, feedback):
73-
inputFile = self.getParameterValue(self.INPUT_LAYER)
74-
zFactor = self.getParameterValue(self.Z_FACTOR)
75-
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
74+
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context))
75+
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
76+
77+
outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
7678

7779
outputFormat = raster.formatShortNameFromFileName(outputFile)
7880

7981
slope = QgsSlopeFilter(inputFile, outputFile, outputFormat)
8082
slope.setZFactor(zFactor)
81-
slope.processRaster(None)
83+
slope.processRaster(feedback)
84+
85+
return {self.OUTPUT: outputFile}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,18 +1044,18 @@ tests:
10441044
hash: 762865ee485a6736d188402aa10e6fd38a812a9e45a7dd2d4885a63a
10451045
type: rasterhash
10461046

1047-
# - algorithm: qgis:slope
1048-
# name: Slope from QGIS analysis library
1049-
# params:
1050-
# INPUT_LAYER:
1051-
# name: dem.tif
1052-
# type: raster
1053-
# Z_FACTOR: 1.0
1054-
# results:
1055-
# OUTPUT_LAYER:
1056-
# hash: 151ea76a21b286c16567eb6b4b692925a84145b65561a0017effb1a1
1057-
# type: rasterhash
1058-
#
1047+
- algorithm: qgis:slope
1048+
name: Slope from QGIS analysis library
1049+
params:
1050+
INPUT_LAYER:
1051+
name: dem.tif
1052+
type: raster
1053+
Z_FACTOR: 1.0
1054+
results:
1055+
OUTPUT_LAYER:
1056+
hash: 151ea76a21b286c16567eb6b4b692925a84145b65561a0017effb1a1
1057+
type: rasterhash
1058+
10591059
# - algorithm: qgis:ruggednessindex
10601060
# name: Ruggedness index from QGIS analysis library
10611061
# params:

0 commit comments

Comments
 (0)