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 CRULE_OPTIONS = [
"overwrite",
"maxndvi",
"maxband",
"minband",
"validband",
"mean",
"mode",
"median",
"sum",
"minallbands",
"maxallbands",
"stdev"]
48 SRCNODATA =
"SRCNODATA" 49 BNDNODATA =
"BNDNODATA" 50 DSTNODATA =
"DSTNODATA" 53 RESAMPLE_OPTIONS = [
'near',
'bilinear']
56 TYPE = [
'none',
'Byte',
'Int16',
'UInt16',
'UInt32',
'Int32',
'Float32',
'Float64',
'CInt16',
'CInt32',
'CFloat32',
'CFloat64']
62 def defineCharacteristics(self):
63 self.
name =
"composite/mosaic raster datasets" 64 self.
group =
"[pktools] raster" 65 self.addParameter(ParameterMultipleInput(self.
INPUT,
'Input layer raster data set',ParameterMultipleInput.TYPE_RASTER))
66 self.addParameter(ParameterSelection(self.
CRULE,
"composite rule",self.
CRULE_OPTIONS, 0))
67 self.addOutput(OutputRaster(self.
OUTPUT,
"Output raster data set"))
68 self.addParameter(ParameterSelection(self.
RTYPE,
'Output raster type (leave as none to keep original type)', self.
TYPE, 0))
69 self.addParameter(ParameterNumber(self.
DX,
"Output resolution in x (leave 0 for no change)",0.0,
None,0.0))
70 self.addParameter(ParameterNumber(self.
DY,
"Output resolution in y (leave 0 for no change)",0.0,
None,0.0))
71 self.addParameter(ParameterExtent(self.
PROJWIN,
72 'Georeferenced boundingbox'))
73 self.addParameter(ParameterString(self.
CB,
"band index(es) used for the composite rule (0 based), e.g., 0;1 in case of maxndvi",
"0"))
74 self.addParameter(ParameterString(self.
SRCNODATA,
"invalid value(s) for input raster dataset (e.g., 0;255)",
"none"))
75 self.addParameter(ParameterString(self.
BNDNODATA,
"Band(s) in input image to check if pixel is valid (e.g., 0;1)",
"0"))
76 self.addParameter(ParameterString(self.
DSTNODATA,
"nodata value to put in output raster dataset if not valid or out of bounds",
"0"))
77 self.addParameter(ParameterString(self.
MINGUI,
"flag values smaller or equal to this value as invalid",
"none"))
78 self.addParameter(ParameterString(self.
MAXGUI,
"flag values larger or equal to this value as invalid",
"none"))
80 self.addParameter(ParameterString(self.
EXTRA,
81 'Additional parameters',
'-of GTiff', optional=
True))
83 def processAlgorithm(self, progress):
84 cliPath =
'"' + os.path.join(pktoolsUtils.pktoolsPath(), self.
cliName()) +
'"' 87 input=self.getParameterValue(self.
INPUT)
88 inputFiles = input.split(
';')
89 for inputFile
in inputFiles:
91 commands.append(
'"' + inputFile +
'"')
93 if self.
TYPE[self.getParameterValue(self.
RTYPE)] !=
"none":
94 commands.append(
'-ot')
95 commands.append(self.
TYPE[self.getParameterValue(self.
RTYPE)])
96 output=self.getOutputValue(self.
OUTPUT)
99 commands.append(
'"' + output +
'"')
100 commands.append(
"-cr")
102 if self.getParameterValue(self.
DX) != 0:
103 commands.append(
"-dx")
104 commands.append(str(self.getParameterValue(self.
DX)))
105 if self.getParameterValue(self.
DY) != 0:
106 commands.append(
"-dy")
107 commands.append(str(self.getParameterValue(self.
DY)))
108 projwin = str(self.getParameterValue(self.
PROJWIN))
109 regionCoords = projwin.split(
',')
110 commands.append(
'-ulx')
111 commands.append(regionCoords[0])
112 commands.append(
'-uly')
113 commands.append(regionCoords[3])
114 commands.append(
'-lrx')
115 commands.append(regionCoords[1])
116 commands.append(
'-lry')
117 commands.append(regionCoords[2])
118 cb=self.getParameterValue(self.
CB)
119 cbValues = cb.split(
';')
120 for cbValue
in cbValues:
121 commands.append(
'-cb')
122 commands.append(cbValue)
123 srcnodata=self.getParameterValue(self.
SRCNODATA)
124 if srcnodata !=
"none":
125 srcnodataValues = srcnodata.split(
';')
126 for srcnodataValue
in srcnodataValues:
127 commands.append(
'-srcnodata')
128 commands.append(srcnodataValue)
129 bndnodata=self.getParameterValue(self.
BNDNODATA)
130 bndnodataValues = bndnodata.split(
';')
131 for bndnodataValue
in bndnodataValues:
132 commands.append(
'-bndnodata')
133 commands.append(bndnodataValue)
134 commands.append(
'-dstnodata')
135 commands.append(self.getParameterValue(self.
DSTNODATA))
137 minGUI=self.getParameterValue(self.
MINGUI)
139 minValues = minGUI.split(
';')
140 for minValue
in minValues:
141 commands.append(
'-min')
142 commands.append(minValue)
143 maxGUI=self.getParameterValue(self.
MAXGUI)
145 maxValues = maxGUI.split(
';')
146 for maxValue
in maxValues:
147 commands.append(
'-max')
148 commands.append(maxValue)
149 commands.append(
"-r")
151 extra = str(self.getParameterValue(self.
EXTRA))
153 commands.append(extra)
155 pktoolsUtils.runpktools(commands, progress)