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)",
"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 smaller 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 commands = [os.path.join(pktoolsUtils.pktoolsPath(), self.
cliName())]
86 input=self.getParameterValue(self.
INPUT)
87 inputFiles = input.split(
';')
88 for inputFile
in inputFiles:
90 commands.append(inputFile)
92 if self.
TYPE[self.getParameterValue(self.
RTYPE)] !=
"none":
93 commands.append(
'-ot')
94 commands.append(self.
TYPE[self.getParameterValue(self.
RTYPE)])
95 output=self.getParameterValue(self.
OUTPUT)
98 commands.append(self.getOutputValue(self.
OUTPUT))
99 commands.append(
"-cr")
101 if self.getParameterValue(self.
DX) != 0:
102 commands.append(
"-dx")
103 commands.append(str(self.getParameterValue(self.
DX)))
104 if self.getParameterValue(self.
DY) != 0:
105 commands.append(
"-dy")
106 commands.append(str(self.getParameterValue(self.
DY)))
107 projwin = str(self.getParameterValue(self.
PROJWIN))
108 regionCoords = projwin.split(
',')
109 commands.append(
'-ulx')
110 commands.append(regionCoords[0])
111 commands.append(
'-uly')
112 commands.append(regionCoords[3])
113 commands.append(
'-lrx')
114 commands.append(regionCoords[1])
115 commands.append(
'-lry')
116 commands.append(regionCoords[2])
117 cb=self.getParameterValue(self.
CB)
118 cbValues = cb.split(
';')
119 for cbValue
in cbValues:
120 commands.append(
'-cb')
121 commands.append(cbValue)
122 srcnodata=self.getParameterValue(self.
SRCNODATA)
123 if srcnodata !=
"none":
124 srcnodataValues = srcnodata.split(
';')
125 for srcnodataValue
in srcnodataValues:
126 commands.append(
'-srcnodata')
127 commands.append(srcnodataValue)
128 bndnodata=self.getParameterValue(self.
BNDNODATA)
129 bndnodataValues = bndnodata.split(
';')
130 for bndnodataValue
in bndnodataValues:
131 commands.append(
'-bndnodata')
132 commands.append(bndnodataValue)
133 commands.append(
'-dstnodata')
134 commands.append(self.getParameterValue(self.
DSTNODATA))
136 minGUI=self.getParameterValue(self.
MINGUI)
138 minValues = minGUI.split(
';')
139 for minValue
in minValues:
140 commands.append(
'-min')
141 commands.append(minValue)
142 maxGUI=self.getParameterValue(self.
MAXGUI)
144 maxValues = maxGUI.split(
';')
145 for maxValue
in maxValues:
146 commands.append(
'-max')
147 commands.append(maxValue)
148 commands.append(
"-r")
150 extra = str(self.getParameterValue(self.
EXTRA))
152 commands.append(extra)
155 for item
in commands:
159 pktoolsUtils.runpktools(commands, progress)