Skip to content

Commit 48c7c49

Browse files
committedOct 11, 2016
[processing] expose Slope from Raster terrain analysis plugin in toolbox
1 parent e76a467 commit 48c7c49

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed
 

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
from .SingleSidedBuffer import SingleSidedBuffer
160160
from .PointsAlongGeometry import PointsAlongGeometry
161161
from .Aspect import Aspect
162+
from .Slope import Slope
162163

163164
pluginPath = os.path.normpath(os.path.join(
164165
os.path.split(os.path.dirname(__file__))[0], os.pardir))
@@ -215,7 +216,7 @@ def __init__(self):
215216
BoundingBox(), Boundary(), PointOnSurface(),
216217
OffsetLine(), PolygonCentroids(), Translate(),
217218
SingleSidedBuffer(), PointsAlongGeometry(),
218-
Aspect(),
219+
Aspect(), Slope(),
219220
]
220221

221222
if hasMatplotlib:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
Slope.py
6+
---------------------
7+
Date : October 2016
8+
Copyright : (C) 2016 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
from builtins import str
20+
21+
__author__ = 'Alexander Bruy'
22+
__date__ = 'October 2016'
23+
__copyright__ = '(C) 2016, Alexander Bruy'
24+
25+
# This will get replaced with a git SHA1 when you do a git archive
26+
27+
__revision__ = '$Format:%H$'
28+
29+
from qgis.analysis import QgsSlopeFilter
30+
31+
from processing.core.GeoAlgorithm import GeoAlgorithm
32+
from processing.core.parameters import ParameterRaster
33+
from processing.core.parameters import ParameterNumber
34+
from processing.core.outputs import OutputRaster
35+
from processing.tools import raster
36+
37+
38+
class Slope(GeoAlgorithm):
39+
40+
INPUT_LAYER = 'INPUT_LAYER'
41+
Z_FACTOR = 'Z_FACTOR'
42+
OUTPUT_LAYER = 'OUTPUT_LAYER'
43+
44+
def defineCharacteristics(self):
45+
self.name, self.i18n_name = self.trAlgorithm('Slope')
46+
self.group, self.i18n_group = self.trAlgorithm('Raster terrain analysis')
47+
48+
self.addParameter(ParameterRaster(self.INPUT_LAYER,
49+
self.tr('Elevation layer')))
50+
self.addParameter(ParameterNumber(self.Z_FACTOR,
51+
self.tr('Z factor'), 1.0, 999999.99, 1.0))
52+
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
53+
self.tr('Slope')))
54+
55+
def processAlgorithm(self, progress):
56+
inputFile = self.getParameterValue(self.INPUT_LAYER)
57+
zFactor = self.getParameterValue(self.Z_FACTOR)
58+
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
59+
60+
outputFormat = raster.formatShortNameFromFileName(outputFile)
61+
62+
slope = QgsSlopeFilter(inputFile, outputFile, outputFormat)
63+
slope.setZFactor(zFactor)
64+
slope.processRaster(None)

0 commit comments

Comments
 (0)
Please sign in to comment.