PyQGIS scripts with OSGeo4W & PyCharm
C:\OSGeo4W64\bin 에 pycharm.bat 생성
@echo off
call "%~dp0\o4w_env.bat"
call "%OSGEO4W_ROOT%\apps\grass\grass78\etc\env.bat"
call qt5_env.bat
call py3_env.bat
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps\grass\grass78\lib;%OSGEO4W_ROOT%\apps\grass\grass78\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
start /d "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\bin" pycharm64.exe
OSGeo4W Shell에서 pycharm 실행
https://anitagraser.com/2019/03/03/stand-alone-pyqgis-scripts-with-osgeo4w/
Stand-alone PyQGIS scripts with OSGeo4W
PyQGIS scripts are great to automate spatial processing workflows. It’s easy to run these scripts inside QGIS but it can be even more convenient to run PyQGIS scripts without even having to l…
anitagraser.com
파이썬 콘솔에서 작동시키기
python-qgis.bat
@echo off
call "%~dp0\o4w_env.bat"
@echo off
path %OSGEO4W_ROOT%\apps\qgis-ltr\bin;%OSGEO4W_ROOT%\apps\grass\grass78\lib;%OSGEO4W_ROOT%\apps\grass\grass78\bin;C:\Program Files\QGIS 3.16.8\apps\qgis-ltr\python\plugins;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis-ltr
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis-ltr\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis-ltr\python;%OSGEO4W_ROOT%\apps\qgis-ltr\python\plugins;%PYTHONPATH%
%OSGEO4W_ROOT%\apps\qgis-ltr\python\plugins;
는 PYTHONPATH와 path 모두 추가해야한다.
qgis-ltr
qgis 폴더명 주의
QGIS 기능 불러오기 위한 기본 세팅
from qgis.core import *
qgs = QgsApplication([], False)
QgsApplication.setPrefixPath("C:\OSGEO4~1\apps\qgis", True)
QgsApplication.initQgis()