TransWikia.com

Error while running gdal:polygonize as a background task

Geographic Information Systems Asked by Taher Alkamel on October 26, 2020

I am trying to run gdal:polygonize as a background task, but I am getting QGIS crashing and giving me this error:

QGIS died on signal 11ptrace: Operation not permitted.
No thread selected
No stack.
gdb returned 256
Aborted (core dumped)

How can I go around debugging this?

this is the code for my plugin’s module:


def polygonise(inputPath, outputPath, style=None):


    task = processingTask(inputPath, outputPath, style) 
    QgsApplication.taskManager().addTask(task)



class processingTask(QgsTask):

    def __init__(self, inputPath, outputPath, style=None):
        QgsTask.__init__(self, "Publish layers")
        self.inputPath = inputPath
        self.outputPath = outputPath
        self.style = style
        self.exception = None
        self.errortrace = None

    def canCancel(self):
        return False

    def run(self):
        try:
            print("start processing")
            processing.run('gdal:polygonize', {'INPUT':self.inputPath,'BAND':1,'FIELD':'DN','EIGHT_CONNECTEDNESS':False,'OUTPUT':self.outputPath})
            print("stop processing2")

            layer = QgsVectorLayer(self.outputPath, "{}_vectorised".format(self.inputPath.name()), "ogr")
            QgsProject.instance().addMapLayer(layer)

            if not layer.isValid():
                print("Layer failed to load!")

            if not (self.style == None):
                categorizedStyling(layer, 'DN', self.style)
            return layer

        except Exception as e:            
            self.exception = e
            self.errortrace = traceback.format_exc()
        return False

    def finished(self, ok):
        if ok:
            print("Task is finished")
        else:
            print("Task has errors")

I have tried both methods (Extending QgsTask and Task from a processing algorithm) listed in the QGSTask documentation and both resulted in the same outcome.

$ qgis --version

QGIS 3.4.14-Madeira 'Madeira' (exported)

One Answer

Try looking at the QgsProcessingAlgRunnerTask https://qgis.org/pyqgis/master/core/QgsProcessingAlgRunnerTask.html . That should do all this for you already.

Answered by ndawson on October 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP