I have a "for" loop included on a "while" loop, and it work when I save the for loop result in a shapefile and I reuse it on the loop like that :
#last step of the "for" loop
alg_params = {
'CRS': None,
'LAYERS': [regroupee, outputs['CalculatriceDeChamp']['OUTPUT']],
'OUTPUT': 'I:/moulin_z/DONNEES/temp_us235/test_iteration_pyqgis/sorties/regroupee_' + str(num_boucle) + str(feature_id) + '.shp'
}
merge = processing.run('native:mergevectorlayers', alg_params, context=context, is_child_algorithm=True)
regroupee = QgsVectorLayer(merge['OUTPUT'], "Regroupee","ogr")
# after the "for" loop
alg_params = {
'EXPRESSION': '\"affectatio\" = \'Non bati\'',
'INPUT': regroupee,
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['ExtractionNonbati'] = processing.run('native:extractbyexpression', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
But when I try to save result layer as temporary output, it work on the loop, but not on the "extract by expression" processing after the "for" loop... :
#last step of the "for" loop
alg_params = {
'CRS': None,
'LAYERS': [regroupee, outputs['CalculatriceDeChamp']['OUTPUT']],
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['Fusionner'] = processing.run('native:mergevectorlayers', alg_params, context=context, is_child_algorithm=True)
regroupee = QgsVectorLayer(outputs['Fusionner']['OUTPUT'], "Regroupee","ogr")
# after the "for" loop
alg_params = {
'EXPRESSION': '\"affectatio\" = \'Non bati\'',
'INPUT': regroupee,
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['ExtractionNonbati'] = processing.run('native:extractbyexpression', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
Error message explain :
Impossible de créer la couche en mémoire. (Impossible to create the memory layer)
Traceback (most recent call last):
File "<string>", line 267, in processAlgorithm
File "C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python/plugins\processing\tools\general.py", line 117, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish=post_process, feedback=feedback, context=context)
File "C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python/plugins\processing\core\Processing.py", line 182, in runAlgorithm
feedback.reportError(msg)
TypeError: reportError(self, error: str, fatalError: bool): not enough arguments
It would be very great if my code could work with temporary output, because it's really faster.