Skip to content
Permalink
Browse files

[processing] restore Slope algorithm

  • Loading branch information
alexbruy committed Jul 15, 2017
1 parent 5f5fc58 commit 05b4cc22bfe075db916c3cb9826af2a175a3640d
@@ -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
@@ -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
@@ -270,6 +270,7 @@ def getAlgs(self):
SelectByAttribute(),
SelectByExpression(),
SimplifyGeometries(),
Slope(),
Smooth(),
SnapGeometriesToLayer(),
SpatialiteExecuteSQL(),
@@ -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'))
@@ -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'
@@ -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}
@@ -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:

0 comments on commit 05b4cc2

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