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' 24 __revision__ =
'$Format:%H$' 27 from pktoolsUtils
import pktoolsUtils
28 from pktoolsAlgorithm
import pktoolsAlgorithm
29 from processing.core.parameters
import ParameterMultipleInput
30 from processing.core.parameters
import ParameterRaster
31 from processing.core.outputs
import OutputRaster
32 from processing.core.parameters
import ParameterSelection
33 from processing.core.parameters
import ParameterNumber
34 from processing.core.parameters
import ParameterString
35 from processing.core.parameters
import ParameterBoolean
36 from processing.core.parameters
import ParameterExtent
42 MSKNODATA =
"MSKNODATA" 44 OPERATOR_OPTIONS = [
"=",
"<",
">",
"!"]
49 TYPE = [
'none',
'Byte',
'Int16',
'UInt16',
'UInt32',
'Int32',
'Float32',
'Float64',
'CInt16',
'CInt32',
'CFloat32',
'CFloat64']
55 def defineCharacteristics(self):
56 self.
name =
"apply mask to raster dataset" 57 self.
group =
"[pktools] raster" 58 self.addParameter(ParameterRaster(self.
INPUT,
'Input layer raster data set',ParameterRaster))
59 self.addParameter(ParameterMultipleInput(self.
MASK,
'Mask(s) to apply',ParameterMultipleInput.TYPE_RASTER))
60 self.addParameter(ParameterString(self.
MSKNODATA,
"Mask value(s), provide value for each mask (e.g., 250;255)",
"1"))
61 self.addParameter(ParameterString(self.
MSKBAND,
"Mask band(s) to read, provide band for each mask (e.g., 0;1)",
"0"))
63 self.addParameter(ParameterString(self.
NODATA,
"nodata value to put in image if not valid",
"0"))
64 self.addOutput(OutputRaster(self.
OUTPUT,
"Output raster data set"))
65 self.addParameter(ParameterSelection(self.
RTYPE,
'Output raster type (leave as none to keep original type)', self.
TYPE, 0))
66 self.addParameter(ParameterString(self.
EXTRA,
67 'Additional parameters',
'-of GTiff', optional=
True))
69 def processAlgorithm(self, progress):
70 cliPath =
'"' + os.path.join(pktoolsUtils.pktoolsPath(), self.
cliName()) +
'"' 73 input=self.getParameterValue(self.
INPUT)
75 commands.append(
'"' + input +
'"')
77 mask=self.getParameterValue(self.
MASK)
78 maskFiles = mask.split(
';')
79 for maskFile
in maskFiles:
81 commands.append(maskFile)
83 commands.append(str(self.getParameterValue(self.
MSKBAND)))
84 mskband=self.getParameterValue(self.
MSKBAND)
85 mskbandValues = mskband.split(
';')
86 for mskbandValue
in mskbandValues:
87 commands.append(
'-mskband')
88 commands.append(mskbandValue)
89 commands.append(str(self.getParameterValue(self.
MSKNODATA)))
90 msknodata=self.getParameterValue(self.
MSKNODATA)
91 msknodataValues = msknodata.split(
';')
92 for msknodataValue
in msknodataValues:
93 commands.append(
'-msknodata')
94 commands.append(msknodataValue)
98 nodata=self.getParameterValue(self.
NODATA)
99 commands.append(
'-nodata')
100 commands.append(nodata)
101 if self.
TYPE[self.getParameterValue(self.
RTYPE)] !=
"none":
102 commands.append(
'-ot')
103 commands.append(self.
TYPE[self.getParameterValue(self.
RTYPE)])
104 output=self.getOutputValue(self.
OUTPUT)
106 commands.append(
"-o")
107 commands.append(
'"' + output +
'"')
109 extra = str(self.getParameterValue(self.
EXTRA))
111 commands.append(extra)
113 pktoolsUtils.runpktools(commands, progress)