file_table_reader/qgis_bootstrap.py

36 lines
955 B
Python
Raw Normal View History

2025-11-26 07:18:46 +00:00
import os
import sys
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
QGIS_APP = "/Applications/QGIS-LTR.app/Contents"
QGIS_PREFIX = f"{QGIS_APP}/Resources"
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
# ==== FIX VERY IMPORTANT ====
os.environ["QGIS_PREFIX_PATH"] = QGIS_PREFIX
os.environ["PROJ_LIB"] = f"{QGIS_PREFIX}/proj"
os.environ["GDAL_DATA"] = f"{QGIS_PREFIX}/gdal"
os.environ["QT_PLUGIN_PATH"] = f"{QGIS_PREFIX}/plugins"
# =============================
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
os.environ["QT_QPA_PLATFORM"] = "offscreen"
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
# Python path
sys.path.append(f"{QGIS_PREFIX}/python")
sys.path.append(f"{QGIS_PREFIX}/python/plugins")
2025-11-25 09:39:21 +00:00
2025-11-29 04:44:08 +00:00
from qgis.core import QgsApplication, QgsProviderRegistry
2025-11-26 07:18:46 +00:00
from qgis.analysis import QgsNativeAlgorithms
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
import processing
from processing.core.Processing import Processing
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
def start_qgis():
qgs = QgsApplication([], False)
qgs.initQgis()
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
# === WAJIB: initialize processing ===
Processing.initialize()
2025-11-29 04:44:08 +00:00
QgsProviderRegistry.instance()
2025-11-26 07:18:46 +00:00
qgs.processingRegistry().addProvider(QgsNativeAlgorithms())
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
return qgs