File: RasterCalculator.py

package info (click to toggle)
qgis 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 374,696 kB
  • ctags: 66,263
  • sloc: cpp: 396,139; ansic: 241,070; python: 130,609; xml: 14,884; perl: 1,290; sh: 1,287; sql: 500; yacc: 268; lex: 242; makefile: 168
file content (79 lines) | stat: -rw-r--r-- 3,063 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-

"""
***************************************************************************
    RasterCalculator.py
    ---------------------
    Date                 : May 2014
    Copyright            : (C) 2014 by Victor Olaya
    Email                : volayaf 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 processing.parameters.ParameterMultipleInput import ParameterMultipleInput
from processing.algs.saga.SagaAlgorithm import SagaAlgorithm
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.parameters.ParameterString import ParameterString
from processing.algs.saga.SagaGroupNameDecorator import SagaGroupNameDecorator

__author__ = 'Victor Olaya'
__date__ = 'May 2014'
__copyright__ = '(C) 2014, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from PyQt4 import QtGui
from processing.parameters.ParameterRaster import ParameterRaster
from processing.outputs.OutputRaster import OutputRaster
from processing.tools.system import *


class RasterCalculator(SagaAlgorithm):


    FORMULA = "FORMULA"
    GRIDS = 'GRIDS'
    XGRIDS = 'XGRIDS'
    RESULT = "RESULT"

    def __init__(self):
        self.allowUnmatchingGridExtents = True
        self.hardcodedStrings = []
        GeoAlgorithm.__init__(self)

    def getCopy(self):
        newone = RasterCalculator()
        newone.provider = self.provider
        return newone

    def defineCharacteristics(self):
        self.name = 'Raster calculator'
        self.cmdname = 'Grid Calculator'
        self.undecoratedGroup = "grid_calculus"
        self.group = SagaGroupNameDecorator.getDecoratedName(self.undecoratedGroup)
        grids = ParameterRaster(self.GRIDS, 'Input layers', True)
        grids.hidden = True
        self.addParameter(grids)
        self.addParameter(ParameterMultipleInput(self.XGRIDS, 'Input layers',
                          ParameterMultipleInput.TYPE_RASTER, False))
        self.addParameter(ParameterString(self.FORMULA, "Formula"))
        self.addOutput(OutputRaster(self.RESULT, "Result"))


    def processAlgorithm(self, progress):
        xgrids = self.getParameterValue(self.XGRIDS)
        layers = xgrids.split(';')
        grid = layers[0]
        self.setParameterValue(self.GRIDS, grid)
        xgrids = ";".join(layers[1:])
        if xgrids == "": xgrids = None
        self.setParameterValue(self.XGRIDS, xgrids)
        SagaAlgorithm.processAlgorithm(self, progress)