Skip to content

Commit 7b74774

Browse files
committed
[processing] expose Relief from Raster terrain analysis plugin in toolbox
1 parent 15902aa commit 7b74774

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
from .Slope import Slope
163163
from .Ruggedness import Ruggedness
164164
from .Hillshade import Hillshade
165+
from .ReliefAuto import ReliefAuto
165166

166167
pluginPath = os.path.normpath(os.path.join(
167168
os.path.split(os.path.dirname(__file__))[0], os.pardir))
@@ -219,6 +220,7 @@ def __init__(self):
219220
OffsetLine(), PolygonCentroids(), Translate(),
220221
SingleSidedBuffer(), PointsAlongGeometry(),
221222
Aspect(), Slope(), Ruggedness(), Hillshade(),
223+
ReliefAuto(),
222224
]
223225

224226
if hasMatplotlib:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
ReliefAuto.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 QgsRelief
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.core.outputs import OutputTable
36+
from processing.tools import raster
37+
38+
39+
class ReliefAuto(GeoAlgorithm):
40+
41+
INPUT_LAYER = 'INPUT_LAYER'
42+
Z_FACTOR = 'Z_FACTOR'
43+
OUTPUT_LAYER = 'OUTPUT_LAYER'
44+
FREQUENCY_DISTRIBUTION = 'FREQUENCY_DISTRIBUTION'
45+
46+
def defineCharacteristics(self):
47+
self.name, self.i18n_name = self.trAlgorithm('Relief (automatic colors)')
48+
self.group, self.i18n_group = self.trAlgorithm('Raster terrain analysis')
49+
50+
self.addParameter(ParameterRaster(self.INPUT_LAYER,
51+
self.tr('Elevation layer')))
52+
self.addParameter(ParameterNumber(self.Z_FACTOR,
53+
self.tr('Z factor'), 1.0, 999999.99, 1.0))
54+
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
55+
self.tr('Refilef')))
56+
self.addOutput(OutputTable(self.FREQUENCY_DISTRIBUTION,
57+
self.tr('Frequesncy distribution')))
58+
59+
def processAlgorithm(self, progress):
60+
inputFile = self.getParameterValue(self.INPUT_LAYER)
61+
zFactor = self.getParameterValue(self.Z_FACTOR)
62+
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
63+
frequencyDistribution = self.getOutputValue(self.FREQUENCY_DISTRIBUTION)
64+
65+
outputFormat = raster.formatShortNameFromFileName(outputFile)
66+
67+
relief = QgsRelief(inputFile, outputFile, outputFormat)
68+
colors = relief.calculateOptimizedReliefClasses()
69+
relief.setReliefColors(colors)
70+
relief.setZFactor(zFactor)
71+
relief.exportFrequencyDistributionToCsv(frequencyDistribution)
72+
relief.processRaster(None)

0 commit comments

Comments
 (0)