Created
June 8, 2024 00:33
-
-
Save ivanlonel/90591aee96777feb3ff0051d549df116 to your computer and use it in GitHub Desktop.
How to run Processing algorithms in standalone PyQGIS applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from pathlib import Path | |
from qgis.core import QgsApplication | |
from qgis.core.contextmanagers import qgisapp | |
with qgisapp(guienabled=False, sysexit=False): | |
# Required before importing processing: | |
sys.path.append(str(Path(QgsApplication.prefixPath()) / "python/plugins")) | |
import processing | |
from processing.core.Processing import Processing | |
Processing.initialize() | |
result = processing.run( | |
"native:stringconcatenation", {"INPUT_1": "Hello ", "INPUT_2": "world!"} | |
) | |
print(result["CONCATENATION"]) | |
print("Execution only reaches this line because we passed sysexit=False above.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment