4***************************************************************************
8 Copyright : (C) 2015 by Pieter Kempeneers
9 Email : kempenep at gmail dot com
10***************************************************************************
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. *
17***************************************************************************
20__author__ = 'Pieter Kempeneers'
21__date__ = 'April 2015'
22__copyright__ = '(C) 2015, Pieter Kempeneers'
23# This will get replaced with a git SHA1 when you do a git archive
24__revision__ = '$Format:%H$'
27from pktoolsUtils import pktoolsUtils
28from pktoolsAlgorithm import pktoolsAlgorithm
29from processing.core.parameters import ParameterMultipleInput
30from processing.core.parameters import ParameterRaster
31from processing.core.outputs import OutputRaster
32from processing.core.parameters import ParameterSelection
33from processing.core.parameters import ParameterNumber
34from processing.core.parameters import ParameterString
35from processing.core.parameters import ParameterBoolean
36from processing.core.parameters import ParameterExtent
38class pkgetmask(pktoolsAlgorithm):
44 OPERATOR_OPTIONS = [
"OR",
"AND"]
50 TYPE = [
'none',
'Byte',
'Int16',
'UInt16',
'UInt32',
'Int32',
'Float32',
'Float64',
'CInt16',
'CInt32',
'CFloat32',
'CFloat64']
56 def defineCharacteristics(self):
57 self.
name =
"create mask from raster dataset"
58 self.
group =
"[pktools] raster"
59 self.addParameter(ParameterRaster(self.
INPUT,
'Input layer raster data set',ParameterRaster))
60 self.addParameter(ParameterString(self.
BAND,
"Band(s) used for mask (e.g., 0;1)",
"0"))
61 self.addParameter(ParameterString(self.
MIN,
"Minimum valid value (one value per band)",
"none"))
62 self.addParameter(ParameterString(self.
MAX,
"Maximum valid value (one value per band)",
"none"))
64 self.addParameter(ParameterString(self.
DATA,
"write value(s) for valid pixels (e.g., 0;255)",
"1"))
65 self.addParameter(ParameterString(self.
NODATA,
"write value(s) for invalid pixels",
"0"))
66 self.addOutput(OutputRaster(self.
OUTPUT,
"Output raster data set"))
67 self.addParameter(ParameterSelection(self.
RTYPE,
'Output raster type (leave as none to keep original type)', self.
TYPE, 0))
68 self.addParameter(ParameterString(self.
EXTRA,
69 'Additional parameters',
'-of GTiff', optional=
True))
71 def processAlgorithm(self, progress):
72 cliPath =
'"' + os.path.join(pktoolsUtils.pktoolsPath(), self.
cliName()) +
'"'
75 input=self.getParameterValue(self.
INPUT)
77 commands.append(
'"' + input +
'"')
79 band=self.getParameterValue(self.
BAND)
80 bandValues = band.split(
';')
81 for bandValue
in bandValues:
82 commands.append(
'-band')
83 commands.append(bandValue)
84 min=self.getParameterValue(self.
MIN)
86 minValues = min.split(
';')
87 for minValue
in minValues:
88 commands.append(
'-min')
89 commands.append(minValue)
90 max=self.getParameterValue(self.
MAX)
92 maxValues = max.split(
';')
93 for maxValue
in maxValues:
94 commands.append(
'-max')
95 commands.append(maxValue)
98 data=self.getParameterValue(self.
DATA)
100 dataValues = data.split(
';')
101 for dataValue
in dataValues:
102 commands.append(
'-data')
103 commands.append(dataValue)
104 nodata=self.getParameterValue(self.
NODATA)
106 nodataValues = nodata.split(
';')
107 for nodataValue
in nodataValues:
108 commands.append(
'-nodata')
109 commands.append(nodataValue)
110 if self.
TYPE[self.getParameterValue(self.
RTYPE)] !=
"none":
111 commands.append(
'-ot')
112 commands.append(self.
TYPE[self.getParameterValue(self.
RTYPE)])
113 output=self.getOutputValue(self.
OUTPUT)
115 commands.append(
"-o")
116 commands.append(
'"' + output +
'"')
118 data=self.getParameterValue(self.
DATA)
120 extra = str(self.getParameterValue(self.
EXTRA))
122 commands.append(extra)
124 pktoolsUtils.runpktools(commands, progress)