Skip to content
Permalink
Browse files

[processing] restore Ruggedness algorithm

  • Loading branch information
alexbruy committed Jul 15, 2017
1 parent 05b4cc2 commit f4bba54a113a1429416cc806ccda41119d9e4427
@@ -72,6 +72,7 @@
from .RandomExtract import RandomExtract
from .RandomExtractWithinSubsets import RandomExtractWithinSubsets
from .RegularPoints import RegularPoints
from .Ruggedness import Ruggedness
from .SaveSelectedFeatures import SaveSelectedFeatures
from .SelectByAttribute import SelectByAttribute
from .SelectByExpression import SelectByExpression
@@ -147,7 +148,6 @@
# from .Translate import Translate
# from .SingleSidedBuffer import SingleSidedBuffer
# from .PointsAlongGeometry import PointsAlongGeometry
# from .Ruggedness import Ruggedness
# from .Hillshade import Hillshade
# from .Relief import Relief
# from .IdwInterpolation import IdwInterpolation
@@ -266,6 +266,7 @@ def getAlgs(self):
RandomExtract(),
RandomExtractWithinSubsets(),
RegularPoints(),
Ruggedness(),
SaveSelectedFeatures(),
SelectByAttribute(),
SelectByExpression(),
@@ -30,21 +30,21 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsRuggednessFilter

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 Ruggedness(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 +56,13 @@ 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('Ruggedness index')))
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('Ruggedness')))

def name(self):
return 'ruggednessindex'
@@ -70,12 +71,15 @@ def displayName(self):
return self.tr('Ruggedness index')

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)

ruggedness = QgsRuggednessFilter(inputFile, outputFile, outputFormat)
ruggedness.setZFactor(zFactor)
ruggedness.processRaster(None)
ruggedness.processRaster(feedback)

return {self.OUTPUT: outputFile}
@@ -1056,18 +1056,18 @@ tests:
hash: 151ea76a21b286c16567eb6b4b692925a84145b65561a0017effb1a1
type: rasterhash

# - algorithm: qgis:ruggednessindex
# name: Ruggedness index from QGIS analysis library
# params:
# INPUT_LAYER:
# name: dem.tif
# type: raster
# Z_FACTOR: 1.0
# results:
# OUTPUT_LAYER:
# hash: ff630246e8dc19c7217d81261c6b64f965c17fa04d3e41d7979c1f1e
# type: rasterhash
#
- algorithm: qgis:ruggednessindex
name: Ruggedness index from QGIS analysis library
params:
INPUT_LAYER:
name: dem.tif
type: raster
Z_FACTOR: 1.0
results:
OUTPUT_LAYER:
hash: ff630246e8dc19c7217d81261c6b64f965c17fa04d3e41d7979c1f1e
type: rasterhash

# - algorithm: qgis:hillshade
# name: Hillshade from QGIS analysis library
# params:

0 comments on commit f4bba54

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