Skip to content

Commit

Permalink
[processing] expose Slope from Raster terrain analysis plugin in toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Oct 11, 2016
1 parent e76a467 commit 48c7c49
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
from .SingleSidedBuffer import SingleSidedBuffer
from .PointsAlongGeometry import PointsAlongGeometry
from .Aspect import Aspect
from .Slope import Slope

pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))
Expand Down Expand Up @@ -215,7 +216,7 @@ def __init__(self):
BoundingBox(), Boundary(), PointOnSurface(),
OffsetLine(), PolygonCentroids(), Translate(),
SingleSidedBuffer(), PointsAlongGeometry(),
Aspect(),
Aspect(), Slope(),
]

if hasMatplotlib:
Expand Down
64 changes: 64 additions & 0 deletions python/plugins/processing/algs/qgis/Slope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
Slope.py
---------------------
Date : October 2016
Copyright : (C) 2016 by Alexander Bruy
Email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
from builtins import str

__author__ = 'Alexander Bruy'
__date__ = 'October 2016'
__copyright__ = '(C) 2016, Alexander Bruy'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from qgis.analysis import QgsSlopeFilter

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputRaster
from processing.tools import raster


class Slope(GeoAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
Z_FACTOR = 'Z_FACTOR'
OUTPUT_LAYER = 'OUTPUT_LAYER'

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Slope')
self.group, self.i18n_group = self.trAlgorithm('Raster terrain analysis')

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')))

def processAlgorithm(self, progress):
inputFile = self.getParameterValue(self.INPUT_LAYER)
zFactor = self.getParameterValue(self.Z_FACTOR)
outputFile = self.getOutputValue(self.OUTPUT_LAYER)

outputFormat = raster.formatShortNameFromFileName(outputFile)

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

0 comments on commit 48c7c49

Please sign in to comment.