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 ParameterRaster
30 from processing.core.parameters
import ParameterVector
31 from processing.core.outputs
import OutputVector
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
92 RULE_OPTIONS = [
'centroid',
'point',
'mean',
'proportion',
'custom',
'min',
'max',
'mode',
'sum',
'median',
'stdev',
'percentile']
98 SRCNODATA =
"SRCNODATA" 99 BNDNODATA =
"BNDNODATA" 105 return "pkextractogr" 107 def defineCharacteristics(self):
108 self.
name =
"extract regular grid" 109 self.
group =
"[pktools] raster/vector" 110 self.addParameter(ParameterRaster(self.
INPUT,
'Input raster data set'))
111 self.addParameter(ParameterSelection(self.
RULE,
"extraction rule",self.
RULE_OPTIONS, 0))
113 self.addOutput(OutputVector(self.
OUTPUT,
'Output vector data set'))
114 self.addParameter(ParameterSelection(self.
FORMAT,
115 'Destination Format', FORMATS))
116 self.addParameter(ParameterBoolean(self.
POLYGON,
"Create OGRPolygon as geometry instead of OGRPoint",
False))
117 self.addParameter(ParameterNumber(self.
BUFFER,
"Buffer for calculating statistics for point features",1,25,1))
118 self.addParameter(ParameterNumber(self.
GRID,
"Cell grid size (in projected units, e.g,. m)",0,1000000,1))
120 self.addParameter(ParameterString(self.
SRCNODATA,
"invalid value(s) for input raster dataset (e.g., 0;255)",
"none"))
121 self.addParameter(ParameterString(self.
BNDNODATA,
"Band(s) in input image to check if pixel is valid (e.g., 0;1)",
"0"))
122 self.addParameter(ParameterString(self.
EXTRA,
'Additional parameters',
'', optional=
True))
124 def processAlgorithm(self, progress):
125 cliPath =
'"' + os.path.join(pktoolsUtils.pktoolsPath(), self.
cliName()) +
'"' 128 input=self.getParameterValue(self.
INPUT)
129 commands.append(
'-i')
130 commands.append(
'"' + input +
'"')
132 commands.append(
"-r")
135 output = self.getOutputFromName(self.
OUTPUT)
136 outFile = output.value
137 formatIdx = self.getParameterValue(self.
FORMAT)
138 outFormat =
'"' + FORMATS[formatIdx] +
'"' 139 commands.append(
'-f')
140 commands.append(outFormat)
141 ext = EXTS[formatIdx]
142 if not outFile.endswith(ext):
144 output.value = outFile
145 commands.append(
'-o')
146 commands.append(
'"' + outFile +
'"')
148 if self.getParameterValue(self.
POLYGON):
149 commands.append(
"-polygon")
150 buffer=self.getParameterValue(self.
BUFFER)
152 commands.append(
"-buf")
153 commands.append(str(buffer))
155 if self.getParameterValue(self.
GRID) > 0:
156 commands.append(
"-grid")
157 commands.append(str(self.getParameterValue(self.
GRID)))
159 srcnodata=self.getParameterValue(self.
SRCNODATA)
160 if srcnodata !=
"none":
161 srcnodataValues = srcnodata.split(
';')
162 for srcnodataValue
in srcnodataValues:
163 commands.append(
'-srcnodata')
164 commands.append(srcnodataValue)
165 bndnodata=self.getParameterValue(self.
BNDNODATA)
166 bndnodataValues = bndnodata.split(
';')
167 for bndnodataValue
in bndnodataValues:
168 commands.append(
'-bndnodata')
169 commands.append(bndnodataValue)
171 extra = str(self.getParameterValue(self.
EXTRA))
173 commands.append(extra)
175 pktoolsUtils.runpktools(commands, progress)