4

With QGIS 3.22 the GRASS algorithms got its own provider (grassprovider.Grass7AlgorithmProvider) and are no more part of processing.algs. Knowing this, in a standalone pyqgis-script I am trying to add the GRASS algs to the processingRegistry with QgsApplication.processingRegistry().addProvider(Grass7AlgorithmProvider()).

If I am now trying to run a GRASS alg, e.g. processing.run("grass7:v.dissolve", ...) I get

_core.QgsProcessingException: Error: Algorithm grass7:v.dissolve not found

When I then list all the registered algs

for alg in QgsApplication.processingRegistry().algorithms():
 print("{}:{} --> {}".format(alg.provider().name(), alg.name(), alg.displayName()))

I get (after the entries of GDAL algs) a list of blank entries:

: -->
: -->
: -->
: -->
...

Obviously the GRASS algs are registered, but with no provider name and with no alg name resulting that I can't call the algs.

Is there anything I am doing wrong or I s it a bug?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 5, 2021 at 13:50
1

1 Answer 1

0

My current setup for the Windows command line:

call "C:\Program Files\QGIS 3.36.1\OSGeo4W.bat"
call "C:\Program Files\QGIS 3.36.1\bin\python-grass83.bat" -c ""
call "C:\Program Files\QGIS 3.36.1\bin\python-qgis.bat" -c ""
python file.py

Content of file.py:

import os
import sys
qgis_root_path = r"C:\Program Files\QGIS 3.36.1"
sys.path.append(os.path.join(qgis_root_path, "apps\qgis\python\plugins"))
from qgis.core import *
QgsApplication.setPrefixPath(qgis_root_path, True)
qgs = QgsApplication([], False)
qgs.initQgis()
import processing
from processing.core.Processing import Processing
Processing.initialize()
for alg in QgsApplication.processingRegistry().algorithms():
 if (alg.id().startswith("grass")):
 print(alg.id(), "->", alg.displayName())
# processing.run("grass:<algorithm.name>", {})
qgs.exitQgis()

Output:

grass:g.extension.list -> g.extension.list
grass:g.extension.manage -> g.extension.manage
grass:g.version -> g.version
...
answered May 27, 2024 at 14:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.