file_table_reader/qgis_bootstrap.py

81 lines
1.9 KiB
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-26 07:18:46 +00:00
from qgis.core import QgsApplication
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()
qgs.processingRegistry().addProvider(QgsNativeAlgorithms())
2025-11-25 09:39:21 +00:00
2025-11-26 07:18:46 +00:00
return qgs
2025-11-25 09:39:21 +00:00
2025-11-25 10:13:09 +00:00
2025-11-25 08:33:38 +00:00
2025-11-25 10:13:09 +00:00
2025-11-25 08:33:38 +00:00
2025-11-26 07:18:46 +00:00
# DEPLOYMENT
# import os
# import sys
2025-11-25 10:17:25 +00:00
2025-11-26 07:18:46 +00:00
# # QGIS environment
# os.environ["QGIS_PREFIX_PATH"] = "/usr"
# os.environ["QGIS_HOME"] = "/usr"
2025-11-25 08:58:08 +00:00
2025-11-26 07:18:46 +00:00
# os.environ["PROJ_LIB"] = "/usr/share/proj"
# os.environ["GDAL_DATA"] = "/usr/share/gdal"
# os.environ["QT_PLUGIN_PATH"] = "/usr/lib/x86_64-linux-gnu/qt5/plugins"
2025-11-25 10:15:23 +00:00
2025-11-26 07:18:46 +00:00
# os.environ["QT_QPA_PLATFORM"] = "offscreen"
2025-11-25 09:51:19 +00:00
2025-11-26 07:18:46 +00:00
# # QGIS Python plugins (THIS IS THE MISSING PART)
# sys.path.append("/usr/share/qgis/python")
# sys.path.append("/usr/share/qgis/python/plugins")
2025-11-25 08:33:38 +00:00
2025-11-26 07:18:46 +00:00
# # Python modules (from system)
# sys.path.append("/usr/lib/python3/dist-packages")
# sys.path.append("/usr/lib/python3/dist-packages/qgis")
# from qgis.core import QgsApplication
# from qgis.analysis import QgsNativeAlgorithms
# import processing
# from processing.core.Processing import Processing
# def start_qgis():
# qgs = QgsApplication([], False)
# qgs.initQgis()
# Processing.initialize()
# qgs.processingRegistry().addProvider(QgsNativeAlgorithms())
# return qgs