55 lines
1.7 KiB
Batchfile
55 lines
1.7 KiB
Batchfile
@echo off
|
||
REM ============================================================
|
||
REM QGIS 子进程启动脚本(Windows)
|
||
REM 自动检测 QGIS 安装结构,支持 qgis-ltr/qgis + Python312/Python39
|
||
REM ============================================================
|
||
|
||
if "%QGIS_ROOT%"=="" goto :no_root
|
||
if not exist "%QGIS_ROOT%" goto :no_root_dir
|
||
|
||
REM --- 检测 QGIS 应用目录 ---
|
||
set "QGIS_APP=%QGIS_ROOT%\apps\qgis-ltr"
|
||
if not exist "%QGIS_APP%" set "QGIS_APP=%QGIS_ROOT%\apps\qgis"
|
||
if not exist "%QGIS_APP%" goto :no_qgis_app
|
||
|
||
REM --- 检测 Python 目录 ---
|
||
set "PY=%QGIS_ROOT%\apps\Python312"
|
||
if not exist "%PY%" set "PY=%QGIS_ROOT%\apps\Python39"
|
||
if not exist "%PY%" set "PY=%QGIS_ROOT%\apps\Python310"
|
||
if not exist "%PY%" set "PY=%QGIS_ROOT%\apps\Python311"
|
||
if not exist "%PY%" goto :no_python
|
||
|
||
REM --- 设置环境 ---
|
||
set "PYTHONHOME=%PY%"
|
||
set "PYTHONPATH=%QGIS_APP%\python"
|
||
set "QGIS_PREFIX_PATH=%QGIS_APP%"
|
||
set "QT_PLUGIN_PATH=%QGIS_APP%\qtplugins;%QGIS_ROOT%\apps\Qt5\plugins"
|
||
set "GDAL_DATA=%QGIS_ROOT%\apps\gdal\share\gdal"
|
||
set "PYTHONUTF8=1"
|
||
set "GDAL_FILENAME_IS_UTF8=YES"
|
||
set "VSI_CACHE=TRUE"
|
||
set "VSI_CACHE_SIZE=1000000"
|
||
set "PATH=%QGIS_APP%\bin;%QGIS_ROOT%\apps\Qt5\bin;%QGIS_ROOT%\apps\gdal\lib;%PATH%"
|
||
REM 强制使用 QGIS 自带的 PROJ,避免 PostgreSQL/PostGIS 的旧 proj.db 干扰
|
||
if exist "%QGIS_ROOT%\share\proj" set "PROJ_DATA=%QGIS_ROOT%\share\proj"
|
||
|
||
REM --- 启动 ---
|
||
"%PY%\python3.exe" %*
|
||
exit /b %ERRORLEVEL%
|
||
|
||
:no_root
|
||
echo [ERROR] QGIS_ROOT 环境变量未设置
|
||
exit /b 1
|
||
|
||
:no_root_dir
|
||
echo [ERROR] QGIS_ROOT 目录不存在: %QGIS_ROOT%
|
||
exit /b 1
|
||
|
||
:no_qgis_app
|
||
echo [ERROR] 未找到 QGIS 应用目录
|
||
exit /b 1
|
||
|
||
:no_python
|
||
echo [ERROR] 未找到 QGIS Python 目录
|
||
exit /b 1
|