I have a snippet that intersects two map layers (blockLayer
and ogLayer
) in QGIS; and prints out when a bad geometry prevents the intersection from occurring. It builds a subclass from QgsProcessingFeedback
, based on the answer posted here by @ndawson.
Here's the code:
class MyFeedBack(QgsProcessingFeedback): # create a subclass from the QgsProcessingFeedback class
def reportError(self, error, fatalError=False): # QgsProcessingFeedback.reportError() is a method
if "invalid geometry" in error:
featNum = error.split("(")[1].split(")")[0]
print("{} has bad geometry".format(featNum))
blockLayer = QgsProject.instance().mapLayersByName("harvestApprovals")[0]
ogLayer = QgsProject.instance().mapLayersByName('Boundary old growth .gdb layer')[0]
#feedback = QgsProcessingFeedback.reportError(self, error, fatalError=False)
#feedback = QgsProcessingFeedback.reportError(error, fatalError=False)
feedback = QgsProcessingFeedback() # instantitate the QgsProcessingFeedback class
print(feedback)
params = {'INPUT':blockLayer,'OVERLAY':ogLayer,'OUTPUT':'TEMPORARY_OUTPUT'}
rslt = processing.run("native:intersection", params, feedback=MyFeedBack())
print("\nDone!")
I'd prefer to create a list to add those numbers to, so as to know which geometries need repair. I'm just not sure how (or if it's possible) to build a list within an instance of a class, and somehow return that list from the class.
Is there some way I could myList.append(featNum)
as the errors are encountered, then get myList
back after the process has run?