HEOPS
HEOPS

Reputation: 1

Endless indexing of point clouds in QGis

I am creating a Qgis plugin that processes point clouds. When creating a QgsPointCloudLayer object in Qgis, indexing of this layer begins. But this indexing reaches 100% and is not completed.

    def processAlgorithm(self, parameters, context, feedback):
        input = self.parameterAsPointCloudLayer(parameters, self.INPUT, context).source()
        output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)

        #processing point cloud
        #...

        # adding layer
        layer = QgsPointCloudLayer(output, "New layer", 'pdal')

        if not layer.isValid():
            feedback.pushInfo("invalid layer!")
        else:
            feedback.pushInfo("layer loaded!")
            QgsProject.instance().addMapLayer(layer)

        return {self.name(): 0}

Endless indexing in Qgis

I was trying to specify the path to the files .las, .laz, .copc.laz, but the result was always the same - endless indexing. If you add this cloud point to Qgis manually (by dragging or layer - > add layer), then everything will work fine. I tried to create a QgsPointCloudLayer in the Python console (which is inside Qgis) and it worked. But it doesn't work inside the plugin.

Upvotes: 0

Views: 46

Answers (1)

Kanash
Kanash

Reputation: 16

Processing algorithms are on a separate thread than QgsInterface. Accessing interface (QgsProject.instance()) from a processing algorithm works poorly and often make Qgis crash.

You should return the layer in a sink at the end of the algorithm. It seems there is an output parameter for Point Cloud (QgsProcessingParameterPointCloudDestination) but it throws an error with las or laz files.

Using QgsProcessingParameterFileDestination doesn't load the PointCloudLayer too.

The best way i found to make your algorithm work the way you want is to force algorithm execution on the interface thread but it freezes your application. You can do that by adding this method to your algorithm :

def flags(self):
    return super().flags() | QgsProcessingAlgorithm.FlagNoThreading

Upvotes: 0

Related Questions