2

I'm writing a script to compute the intervisibility between two sets of points using the Intervisibility algorithm from the Visibility Analysis plugin which (to my knowledge) is installed by default in QGIS and available in the processing toolbox.

It needs to be standalone because I intend to pipeline and parallelize the process and don't want the interface/overhead of the application. Using the in-application python console to list the available algorithms,

for alg in QgsApplication.processingRegistry().algorithms():
    print(f"{alg.id()} --> {alg.displayName()}")

I get the following options at the end of the list.

...
qgis:vectorlayerscatterplot --> Vector layer scatterplot
qgis:voronoipolygons --> Voronoi polygons
visibility:Intervisibility --> Intervisibility network
visibility:Viewshed --> Viewshed
visibility:create_viewpoints --> Create viewpoints

I understand that to use these algorithms in the standalone script I need to add the algorithms provider. I do so using the following code.

import os
import sys

sys.path.append(os.path.abspath('/home/USER/.local/share/QGIS/QGIS3/profiles/default/python/plugins/'))

from qgis.core import QgsApplication

from ViewshedAnalysis.visibility_provider import VisibilityProvider
from qgis.analysis import QgsNativeAlgorithms
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(VisibilityProvider())
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())

However, the same code to list the algorithms now ends with,

...
qgis:vectorlayerscatterplot --> Vector layer scatterplot
qgis:voronoipolygons --> Voronoi polygons
: --> 
: --> 
: --> 

And, calls to visibility:Intervisibility fail with Algorithm not found error. What am I missing?

0

1 Answer 1

2

Replace the part

QgsApplication.processingRegistry().addProvider(VisibilityProvider())

with the following

visibilityProvider = VisibilityProvider()
visibilityProvider.setActive(True)
QgsApplication.processingRegistry().addProvider(visibilityProvider)

FYI, deduced from https://github.com/zoran-cuckovic/QGIS-visibility-analysis/blob/master/visibility_provider.py#L82

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.