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