I have two layers, layer_a
and layer_b
. Both have invalid geometries. When I run a processing tool, it throws an error as expected.
Based on the answer posted here by @ndawson, if you subclass QgsProcessingFeedback
, you can implement your own custom logic dealing with the error.
class MyFeedBack(QgsProcessingFeedback): def reportError(self, error, fatalError=False): print(error) ... res = processing.run("TOOL_NAME", params, feedback=MyFeedBack())
When I run the following script in QGIS Python Editor
class MyFeedBack(QgsProcessingFeedback):
def reportError(self, error, fatalError=False):
print("ERROR! ERROR!")
layer_a = QgsProject.instance().mapLayersByName("a")[0]
layer_b = QgsProject.instance().mapLayersByName('b')[0]
feedback = MyFeedBack()
params = {'INPUT': layer_a, 'OVERLAY': layer_b, 'OUTPUT': 'TEMPORARY_OUTPUT'}
rslt = processing.run("native:intersection", params, feedback=feedback)
print("\nDone!")
I get this error:
Traceback (most recent call last):
File "/usr/lib/python3.8/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 9, in <module>
File "/usr/share/qgis/python/plugins/processing/tools/general.py", line 108, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "/usr/share/qgis/python/plugins/processing/core/Processing.py", line 159, in runAlgorithm
ret, results = execute(alg, parameters, context, feedback, catch_exceptions=False)
File "/usr/share/qgis/python/plugins/processing/gui/AlgorithmExecutor.py", line 71, in execute
results, ok = alg.run(parameters, context, feedback, {}, False)
_core.QgsProcessingException: Feature (0) from “b” has invalid geometry. Please fix the geometry or change the Processing setting to the “Ignore invalid input features” option.
According to documentation, reportError
method should run in case of any error. But the method never runs although the processing tool throws an error.
What am I doing wrong?
I use
QGIS 3.16.2-Hannover, Ubuntu 20.04.1 LTS
QGIS 3.16.0-Hannover, Windows 10 x64