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$' 31 from pktoolsUtils
import pktoolsUtils
32 from pktoolsAlgorithm
import pktoolsAlgorithm
33 from processing.core.parameters
import ParameterRaster
34 from processing.core.parameters
import ParameterVector
35 from processing.core.outputs
import OutputVector
36 from processing.core.outputs
import OutputFile
38 from processing.core.parameters
import ParameterSelection
39 from processing.core.parameters
import ParameterNumber
40 from processing.core.parameters
import ParameterString
41 from processing.core.parameters
import ParameterBoolean
42 from processing.core.parameters
import ParameterExtent
96 REFERENCE =
"REFERENCE" 102 CMOUTPUT =
"CMOUTPUT" 103 CMFORMAT_OPTIONS = [
"ascii",
"latex"]
104 CMFORMAT =
"CMFORMAT" 107 LABELCLASS =
"LABELCLASS" 113 def defineCharacteristics(self):
114 self.
name =
"Accuracy assessment with ground reference" 115 self.
group =
"[pktools] supervised classification" 116 self.addParameter(ParameterRaster(self.
INPUT,
'Classification result (raster map)'))
117 self.addParameter(ParameterVector(self.
REFERENCE,
'Labeled reference vector data set'))
118 self.addParameter(ParameterBoolean(self.
ITERATE,
"Iterate over all layers",
True))
119 self.addParameter(ParameterString(self.
LABELREF,
"Attribute name of the reference label",
"label"))
120 self.addParameter(ParameterString(self.
NODATA,
"No data value(s) in input or reference dataset to ignore (e.g., 0;255)",
"0"))
121 self.addOutput(OutputFile(self.
CMOUTPUT, self.tr(
"Confusion matrix output file ")))
125 self.addOutput(OutputVector(self.
OUTPUT,
'Assessment output vector data set'))
126 self.addParameter(ParameterSelection(self.
FORMAT,
127 'Assessment output vector Format', FORMATS))
128 self.addParameter(ParameterString(self.
LABELCLASS,
"Attribute name of classified (map) label",
"class"))
129 self.addParameter(ParameterString(self.
EXTRA,
130 'Additional parameters',
'', optional=
True))
132 def processAlgorithm(self, progress):
133 cliPath =
'"' + os.path.join(pktoolsUtils.pktoolsPath(), self.
cliName()) +
'"' 137 input=self.getParameterValue(self.
INPUT)
138 commands.append(
'-i')
139 commands.append(
'"' + input +
'"')
141 reference=self.getParameterValue(self.
REFERENCE)
142 if self.getParameterValue(self.
ITERATE):
143 if str(reference).find(
'|')>0:
144 referencename=str(reference)[:str(reference).find(
'|')]
146 referencename=str(reference)
148 referencename=str(reference).replace(
"|layername",
" -ln")
149 commands.append(
'-ref')
150 commands.append(referencename)
152 commands.append(
'-lr');
153 commands.append(self.getParameterValue(self.
LABELREF))
155 nodata=self.getParameterValue(self.
NODATA)
157 nodataValues = nodata.split(
';')
158 for nodataValue
in nodataValues:
159 commands.append(
'-nodata')
160 commands.append(nodataValue)
162 commands.append(
"-cm")
163 commands.append(
"-cmf")
165 commands.append(
"-cmo")
166 commands.append(self.getOutputValue(self.
CMOUTPUT))
168 output = self.getOutputFromName(self.
OUTPUT)
169 outFile = output.value
170 formatIdx = self.getParameterValue(self.
FORMAT)
171 outFormat =
'"' + FORMATS[formatIdx] +
'"' 172 commands.append(
'-f')
173 commands.append(outFormat)
174 ext = EXTS[formatIdx]
175 if not outFile.endswith(ext):
177 output.value = outFile
178 commands.append(
'-o')
179 commands.append(
'"' + outFile +
'"')
180 commands.append(
'-lc');
181 commands.append(self.getParameterValue(self.
LABELCLASS))
183 extra = str(self.getParameterValue(self.
EXTRA))
185 commands.append(extra)
187 pktoolsUtils.runpktools(commands, progress)