def __init__(self, alg, iterParam=None, parent=None): QThread.__init__(self, parent) self.algorithm = alg self.parameterToIterate = iterParam class Progress: def __init__(self, algex): self.algorithmExecutor = algex def setText(self, text): self.algorithmExecutor.textChanged.emit(text) def setPercentage(self, p): self.algorithmExecutor.percentageChanged.emit(p) def setInfo(self, info): self.algorithmExecutor.infoSet.emit(info) def setCommand(self, cmd): self.algorithmExecutor.commandSet.emit(cmd) def setDebugInfo(self, info): self.algorithmExecutor.debugInfoSet.emit(info) def setConsoleInfo(self, info): self.algorithmExecutor.consoleInfoSet.emit(info) self.progress = Progress(self) if self.parameterToIterate: self.run = self.runalgIterating #generate all single-feature layers settings = QSettings() systemEncoding = settings.value("/UI/encoding", "System").toString() layerfile = alg.getParameterValue(self.parameterToIterate) layer = QGisLayers.getObjectFromUri(layerfile, False) provider = layer.dataProvider() features = getfeatures(layer) self.filelist = [] for feat in features: output = SextanteUtils.getTempFilename("shp") self.filelist.append(output) writer = QgsVectorFileWriter(output, systemEncoding, provider.fields(), provider.geometryType(), layer.crs()) writer.addFeature(feat) del writer else: self.run = self.runalg self.internalError.connect(self.raiseInternalError)
def runalgIterating(alg, paramToIter, progress): #generate all single-feature layers settings = QSettings() systemEncoding = settings.value("/UI/encoding", "System") layerfile = alg.getParameterValue(paramToIter) layer = QGisLayers.getObjectFromUri(layerfile, False) feat = QgsFeature() filelist = [] outputs = {} provider = layer.dataProvider() features = getfeatures(layer) for feat in features: output = SextanteUtils.getTempFilename("shp") filelist.append(output) writer = QgsVectorFileWriter(output, systemEncoding, provider.fields(), provider.geometryType(), layer.crs()) writer.addFeature(feat) del writer #store output values to use them later as basenames for all outputs for out in alg.outputs: outputs[out.name] = out.value #now run all the algorithms i = 1 for f in filelist: alg.setParameterValue(paramToIter, f) for out in alg.outputs: filename = outputs[out.name] if filename: filename = filename[:filename.rfind(".")] + "_" + str( i) + filename[filename.rfind("."):] out.value = filename progress.setText("Executing iteration " + str(i) + "/" + str(len(filelist)) + "...") progress.setPercentage((i * 100) / len(filelist)) if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()): SextantePostprocessing.handleAlgorithmResults( alg, progress, False) i += 1 else: return False return True
def __init__(self, alg, iterParam = None, parent = None): QThread.__init__(self, parent) self.algorithm = alg self.parameterToIterate = iterParam class Progress: def __init__(self, algex): self.algorithmExecutor = algex def setText(self, text): self.algorithmExecutor.textChanged.emit(text) def setPercentage(self, p): self.algorithmExecutor.percentageChanged.emit(p) def setInfo(self, info): self.algorithmExecutor.infoSet.emit(info) def setCommand(self, cmd): self.algorithmExecutor.commandSet.emit(cmd) def setDebugInfo(self, info): self.algorithmExecutor.debugInfoSet.emit(info) def setConsoleInfo(self, info): self.algorithmExecutor.consoleInfoSet.emit(info) self.progress = Progress(self) if self.parameterToIterate: self.run = self.runalgIterating #generate all single-feature layers settings = QSettings() systemEncoding = settings.value( "/UI/encoding", "System" ) layerfile = alg.getParameterValue(self.parameterToIterate) layer = QGisLayers.getObjectFromUri(layerfile, False) provider = layer.dataProvider() features = getfeatures(layer) self.filelist = [] for feat in features: output = SextanteUtils.getTempFilename("shp") self.filelist.append(output) writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), layer.crs() ) writer.addFeature(feat) del writer else: self.run = self.runalg self.internalError.connect(self.raiseInternalError)
def runalgIterating(alg,paramToIter,progress): #generate all single-feature layers settings = QSettings() systemEncoding = settings.value( "/UI/encoding", "System" ) layerfile = alg.getParameterValue(paramToIter) layer = QGisLayers.getObjectFromUri(layerfile, False) feat = QgsFeature() filelist = [] outputs = {} provider = layer.dataProvider() features = getfeatures(layer) for feat in features: output = SextanteUtils.getTempFilename("shp") filelist.append(output) writer = QgsVectorFileWriter(output, systemEncoding, provider.fields(), provider.geometryType(), layer.crs() ) writer.addFeature(feat) del writer #store output values to use them later as basenames for all outputs for out in alg.outputs: outputs[out.name] = out.value #now run all the algorithms i = 1 for f in filelist: alg.setParameterValue(paramToIter, f) for out in alg.outputs: filename = outputs[out.name] if filename: filename = filename[:filename.rfind(".")] + "_" + str(i) + filename[filename.rfind("."):] out.value = filename progress.setText("Executing iteration " + str(i) + "/" + str(len(filelist)) + "...") progress.setPercentage((i * 100) / len(filelist)) if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()): SextantePostprocessing.handleAlgorithmResults(alg, progress, False) i+=1 else: return False; return True