|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + RasterCalculator.py |
| 6 | + --------------------- |
| 7 | + Date : May 2014 |
| 8 | + Copyright : (C) 2014 by Victor Olaya |
| 9 | + Email : volayaf 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 processing.parameters.ParameterMultipleInput import ParameterMultipleInput |
| 20 | +from processing.algs.saga.SagaAlgorithm import SagaAlgorithm |
| 21 | +from processing.core.GeoAlgorithm import GeoAlgorithm |
| 22 | +from processing.parameters.ParameterString import ParameterString |
| 23 | +from processing.algs.saga.SagaGroupNameDecorator import SagaGroupNameDecorator |
| 24 | + |
| 25 | +__author__ = 'Victor Olaya' |
| 26 | +__date__ = 'May 2014' |
| 27 | +__copyright__ = '(C) 2014, Victor Olaya' |
| 28 | + |
| 29 | +# This will get replaced with a git SHA1 when you do a git archive |
| 30 | + |
| 31 | +__revision__ = '$Format:%H$' |
| 32 | + |
| 33 | +from PyQt4 import QtGui |
| 34 | +from processing.parameters.ParameterRaster import ParameterRaster |
| 35 | +from processing.outputs.OutputRaster import OutputRaster |
| 36 | +from processing.tools.system import * |
| 37 | + |
| 38 | + |
| 39 | +class RasterCalculator(SagaAlgorithm): |
| 40 | + |
| 41 | + |
| 42 | + FORMULA = "FORMULA" |
| 43 | + GRIDS = 'GRIDS' |
| 44 | + XGRIDS = 'XGRIDS' |
| 45 | + RESULT = "RESULT" |
| 46 | + |
| 47 | + def __init__(self): |
| 48 | + self.allowUnmatchingGridExtents = True |
| 49 | + self.hardcodedStrings = [] |
| 50 | + GeoAlgorithm.__init__(self) |
| 51 | + |
| 52 | + def getCopy(self): |
| 53 | + newone = RasterCalculator() |
| 54 | + newone.provider = self.provider |
| 55 | + return newone |
| 56 | + |
| 57 | + def defineCharacteristics(self): |
| 58 | + self.name = 'Raster calculator' |
| 59 | + self.cmdname = 'Grid Calculator' |
| 60 | + self.undecoratedGroup = "grid_calculus" |
| 61 | + self.group = SagaGroupNameDecorator.getDecoratedName(self.undecoratedGroup) |
| 62 | + grids = ParameterRaster(self.GRIDS, 'Input layers', True) |
| 63 | + grids.hidden = True |
| 64 | + self.addParameter(grids) |
| 65 | + self.addParameter(ParameterMultipleInput(self.XGRIDS, 'Input layers', |
| 66 | + ParameterMultipleInput.TYPE_RASTER, False)) |
| 67 | + self.addParameter(ParameterString(self.FORMULA, "Formula")) |
| 68 | + self.addOutput(OutputRaster(self.RESULT, "Result")) |
| 69 | + |
| 70 | + |
| 71 | + def processAlgorithm(self, progress): |
| 72 | + xgrids = self.getParameterValue(self.XGRIDS) |
| 73 | + layers = xgrids.split(';') |
| 74 | + grid = layers[0] |
| 75 | + self.setParameterValue(self.GRIDS, grid) |
| 76 | + xgrids = ";".join(layers[1:]) |
| 77 | + if xgrids == "": xgrids = None |
| 78 | + self.setParameterValue(self.XGRIDS, xgrids) |
| 79 | + SagaAlgorithm.processAlgorithm(self, progress) |
0 commit comments