Skip to content

Commit e6ba405

Browse files
committedOct 13, 2013
[processing] add gdal slope algorithm (addresses #7201)
1 parent ef2963c commit e6ba405

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed
 

‎python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from processing.gdal.extractprojection import ExtractProjection
5656
from processing.gdal.gdal2xyz import gdal2xyz
5757
from processing.gdal.hillshade import hillshade
58+
from processing.gdal.slope import slope
5859

5960
from processing.gdal.ogr2ogr import Ogr2Ogr
6061
from processing.gdal.ogrinfo import OgrInfo
@@ -106,7 +107,7 @@ def createAlgsList(self):
106107
rgb2pct(), pct2rgb(), merge(), polygonize(), gdaladdo(),
107108
ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
108109
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
109-
hillshade(),
110+
hillshade(), slope(),
110111
# ----- OGR tools -----
111112
OgrInfo(), Ogr2Ogr(), OgrSql(),
112113
]
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
slope.py
6+
---------------------
7+
Date : October 2013
8+
Copyright : (C) 2013 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+
20+
__author__ = 'Alexander Bruy'
21+
__date__ = 'October 2013'
22+
__copyright__ = '(C) 2013, Alexander Bruy'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
29+
from PyQt4.QtGui import *
30+
31+
from processing.core.GeoAlgorithm import GeoAlgorithm
32+
from processing.parameters.ParameterRaster import ParameterRaster
33+
from processing.parameters.ParameterBoolean import ParameterBoolean
34+
from processing.parameters.ParameterNumber import ParameterNumber
35+
from processing.outputs.OutputRaster import OutputRaster
36+
from processing.gdal.GdalUtils import GdalUtils
37+
from processing.tools.system import *
38+
39+
40+
class slope(GeoAlgorithm):
41+
42+
INPUT = 'INPUT'
43+
BAND = 'BAND'
44+
COMPUTE_EDGES = 'COMPUTE_EDGES'
45+
ZEVENBERGEN = 'ZEVENBERGEN'
46+
AS_PERCENT = 'AS_PERCENT'
47+
SCALE = 'SCALE'
48+
OUTPUT = 'OUTPUT'
49+
50+
#def getIcon(self):
51+
# filepath = os.path.dirname(__file__) + '/icons/dem.png'
52+
# return QIcon(filepath)
53+
54+
def defineCharacteristics(self):
55+
self.name = 'Slope'
56+
self.group = '[GDAL] Analysis'
57+
self.addParameter(ParameterRaster(self.INPUT, 'Input layer'))
58+
self.addParameter(ParameterNumber(self.BAND, 'Band number', 1, 99, 1))
59+
self.addParameter(ParameterBoolean(self.COMPUTE_EDGES, 'Compute edges',
60+
False))
61+
self.addParameter(ParameterBoolean(self.ZEVENBERGEN,
62+
"Use Zevenbergen&Thorne formula (instead of the Horn's one)",
63+
False))
64+
self.addParameter(ParameterBoolean(self.AS_PERCENT,
65+
'Slope expressed as percent (instead of degrees)',
66+
False))
67+
self.addParameter(ParameterNumber(self.SCALE,
68+
'Scale (ratio of vert. units to horiz.)', 0.0,
69+
99999999.999999, 1.0))
70+
71+
self.addOutput(OutputRaster(self.OUTPUT, 'Output file'))
72+
73+
def processAlgorithm(self, progress):
74+
arguments = ['slope']
75+
arguments.append(unicode(self.getParameterValue(self.INPUT)))
76+
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))
77+
78+
arguments.append('-b')
79+
arguments.append(str(self.getParameterValue(self.BAND)))
80+
arguments.append('-s')
81+
arguments.append(str(self.getParameterValue(self.SCALE)))
82+
83+
if self.getParameterValue(self.COMPUTE_EDGES):
84+
arguments.append('-compute_edges')
85+
86+
if self.getParameterValue(self.ZEVENBERGEN):
87+
arguments.append('-alg')
88+
arguments.append('ZevenbergenThorne')
89+
90+
if self.getParameterValue(self.AS_PERCENT):
91+
arguments.append('-p')
92+
93+
GdalUtils.runGdal(['gdaldem',
94+
GdalUtils.escapeAndJoin(arguments)], progress)

0 commit comments

Comments
 (0)
Please sign in to comment.