1

I'm developing a standalone QGIS application and I want to run the tessellate (3d:tessellate) processing tool using the following code: 

import processing
from qgis.analysis import QgsNativeAlgorithms
from qgis.core import QgsApplication
from processing.core.Processing import Processing

# Supply path to qgis install location
QgsApplication.setPrefixPath("C:\\OSGEO4~1\\apps\\qgis", True)

profile_folder = '.'
# Create a reference to the QgsApplication.  Setting the second argument to False disables the GUI.
app = QgsApplication([], False, profile_folder)

# Load providers
app.initQgis()

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
processing.run("gdal:aspect", {'INPUT': 'D:/OneDrive/Personnel/Daniel/QGIS/Kingston/Kingston_sub9.gpkg|layername=Road', 'OUTPUT': 'TEMPORARY_OUTPUT'})

# Stop QGIS appllication
app.exitQgis()
app.exit()

I received the following error message saying it cannot find the algorithm:

C:\OSGeo4W64\apps\Python37\python.exe C:/Users/berge/PycharmProjects/qgis_geo_sim/runner_chordal_axis.py
C:\OSGeo4W64\apps\qgis\python\qgis\utils.py:744: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  mod = _builtin_import(name, globals, locals, fromlist, level)
Traceback (most recent call last):
  File "C:/Users/berge/PycharmProjects/qgis_geo_sim/runner_chordal_axis.py", line 19, in <module>
    processing.run("3d:tessellate", {'INPUT': 'D:/OneDrive/Personnel/Daniel/QGIS/Kingston/Kingston_sub9.gpkg|layername=Road', 'OUTPUT': 'TEMPORARY_OUTPUT'})
  File "C:\OSGeo4W64\apps\qgis\python\plugins\processing\tools\general.py", line 106, in run
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
  File "C:\OSGeo4W64\apps\qgis\python\plugins\processing\core\Processing.py", line 125, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException: Error: Algorithm 3d:tessellate not found

But I can run the same processing tool code in the QGIS python console and it's working fine:

processing.run("3d:tessellate", {'INPUT':'D:/OneDrive/Personnel/Daniel/QGIS/Kingston/Kingston_sub9.gpkg|layername=Road','OUTPUT':'TEMPORARY_OUTPUT'})

When I run the following code in the QGIS python console I can "see" what are the runnable processing tools and of course 3d:tessellate is there

for algo in QgsApplication.processingRegistry().algorithms():
    print(algo.id(), "------", algo.displayName())


3d:tessellate ------ Tessellate
gdal:aspect ------ Aspect
...passing 950 lines...
saga:zonalmultipleregressionanalysispointsandpredictorgrids ------ Zonal multiple regression analysis (points and predictor grids)
saga:zonalrasterstatistics ------ Zonal raster statistics

When I run the almost same code in a QGIS stansdalone script I have the following output and do not see the 3d:tessellate processing tool.

gdal:aspect ------ Aspect
gdal:assignprojection ------ Assign projection
... passing 949 lines...
saga:zonalmultipleregressionanalysispointsandpredictorgrids ------ Zonal multiple regression analysis (points and predictor grids)
saga:zonalrasterstatistics ------ Zonal raster statistics

What is wrong? Why I cannot "see" and use the tessellate "3d:tessellate" processing tool in a QGIS standalone application?

I used the following for this test:

  • OS: Windows 10
  • Version: QGIS 3.12
  • Installation: OSGeo4W64

1 Answer 1

2

Because 3d is not part of the "native" plugins you load when executing PyQGIS in standalone (or the namespace of the functions will be native:tessellate instead of 3d:tessellate When you look at the code, you see that you would need a Qgs3DAlgorithms https://github.com/qgis/QGIS/blob/3b3c7d8012407e14fb24b684bb8a623836202f4a/src/process/qgsprocess.cpp#L174 Infortunately, you need sip bindings to expose the C function to Python and it's not the case at the moment. You may do a feature request or make a PR to support 3D algorithm within PyQGIS on the official tracker https://github.com/qgis/QGIS/issues

2

Your Answer

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

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