Skip to content
Permalink
Browse files

[processing] expose Relief from Raster terrain analysis plugin in too…

…lbox
  • Loading branch information
alexbruy committed Oct 11, 2016
1 parent 15902aa commit 7b747743221ddb82fefad9732eabdccfc75eed22
@@ -162,6 +162,7 @@
from .Slope import Slope
from .Ruggedness import Ruggedness
from .Hillshade import Hillshade
from .ReliefAuto import ReliefAuto

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

if hasMatplotlib:
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
ReliefAuto.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 QgsRelief

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.core.outputs import OutputTable
from processing.tools import raster


class ReliefAuto(GeoAlgorithm):

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

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Relief (automatic colors)')
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('Refilef')))
self.addOutput(OutputTable(self.FREQUENCY_DISTRIBUTION,
self.tr('Frequesncy distribution')))

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

outputFormat = raster.formatShortNameFromFileName(outputFile)

relief = QgsRelief(inputFile, outputFile, outputFormat)
colors = relief.calculateOptimizedReliefClasses()
relief.setReliefColors(colors)
relief.setZFactor(zFactor)
relief.exportFrequencyDistributionToCsv(frequencyDistribution)
relief.processRaster(None)

0 comments on commit 7b74774

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