Skip to content

Commit

Permalink
[processing] restore Slope algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jul 15, 2017
1 parent 5f5fc58 commit 05b4cc2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
3 changes: 2 additions & 1 deletion python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -76,6 +76,7 @@
from .SelectByAttribute import SelectByAttribute
from .SelectByExpression import SelectByExpression
from .SimplifyGeometries import SimplifyGeometries
from .Slope import Slope
from .Smooth import Smooth
from .SnapGeometries import SnapGeometriesToLayer
from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
Expand Down Expand Up @@ -146,7 +147,6 @@
# from .Translate import Translate
# from .SingleSidedBuffer import SingleSidedBuffer
# from .PointsAlongGeometry import PointsAlongGeometry
# from .Slope import Slope
# from .Ruggedness import Ruggedness
# from .Hillshade import Hillshade
# from .Relief import Relief
Expand Down Expand Up @@ -270,6 +270,7 @@ def getAlgs(self):
SelectByAttribute(),
SelectByExpression(),
SimplifyGeometries(),
Slope(),
Smooth(),
SnapGeometriesToLayer(),
SpatialiteExecuteSQL(),
Expand Down
36 changes: 20 additions & 16 deletions python/plugins/processing/algs/qgis/Slope.py
Expand Up @@ -30,21 +30,22 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsSlopeFilter

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 Slope(QgisAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
INPUT = 'INPUT'
Z_FACTOR = 'Z_FACTOR'
OUTPUT_LAYER = 'OUTPUT_LAYER'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'dem.png'))
Expand All @@ -56,12 +57,12 @@ 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.addOutput(OutputRaster(self.OUTPUT_LAYER,
self.tr('Slope')))
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(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Slope')))

def name(self):
return 'slope'
Expand All @@ -70,12 +71,15 @@ def displayName(self):
return self.tr('Slope')

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, context))
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)

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

outputFormat = raster.formatShortNameFromFileName(outputFile)

slope = QgsSlopeFilter(inputFile, outputFile, outputFormat)
slope.setZFactor(zFactor)
slope.processRaster(None)
slope.processRaster(feedback)

return {self.OUTPUT: outputFile}
24 changes: 12 additions & 12 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Expand Up @@ -1044,18 +1044,18 @@ tests:
hash: 762865ee485a6736d188402aa10e6fd38a812a9e45a7dd2d4885a63a
type: rasterhash

# - algorithm: qgis:slope
# name: Slope from QGIS analysis library
# params:
# INPUT_LAYER:
# name: dem.tif
# type: raster
# Z_FACTOR: 1.0
# results:
# OUTPUT_LAYER:
# hash: 151ea76a21b286c16567eb6b4b692925a84145b65561a0017effb1a1
# type: rasterhash
#
- algorithm: qgis:slope
name: Slope from QGIS analysis library
params:
INPUT_LAYER:
name: dem.tif
type: raster
Z_FACTOR: 1.0
results:
OUTPUT_LAYER:
hash: 151ea76a21b286c16567eb6b4b692925a84145b65561a0017effb1a1
type: rasterhash

# - algorithm: qgis:ruggednessindex
# name: Ruggedness index from QGIS analysis library
# params:
Expand Down

0 comments on commit 05b4cc2

Please sign in to comment.