0

When developing an application (e.g., custom algorithms) that rely on a custom processing provider (e.g., WhiteBox tools), it can be useful to run/develop as a standalone app (i.e., not within QGIS). How can I call whitebox QGIS algorithims in my standalone tests?

import pytest #pytest-qgis also installed

@pytest.fixture(scope='session')
def qproj(qgis_app, qgis_processing):
    
    from qgis import processing
    processing.run('wbt:ConvertNodataToZero', { 'input' : r'path/layer.tif', 'output' : 'TEMPORARY_OUTPUT'})

this fails with _core.QgsProcessingException: Error: Algorithm wbt:ConvertNodataToZero not found

1 Answer 1

0

first, ensure the QGIS user path where the wbt plugin is installed is added to your PYTHONPATH (e.g., c:\Users\cefect\AppData\Local\QGIS\QGIS3\profiles\dev\python\plugins).

then, create a fixture that adds the custom provider and sets your wbt executable location:


@pytest.fixture(scope='session')
def wbt_init(qgis_app, qgis_processing):
    """initilze the WhiteBoxTools processing provider"""
    
    #load the provider
    from wbt_for_qgis.wbtprovider import WbtProvider #be sure to add the profile folder to sys.path
    whitebox_provider = WbtProvider()
    
    #add to the registry
    assert qgis_app.processingRegistry().addProvider(whitebox_provider)
    
    #add the exe setting
    from processing.core.ProcessingConfig import ProcessingConfig
    wbt_exe = r'l:\06_SOFT\whitebox\v2.2.0\whitebox_tools.exe'    
    ProcessingConfig.setSettingValue('WBT_EXECUTABLE', wbt_exe)
    
    return whitebox_provider #needs to be held somewhere

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.