I am trying to run a standalone script to run PyQGIS 3.22 processes faster.
Call PyQgis.bat via cmd:
@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W
SET QGISNAME=qgis-ltr
SET QGIS=%OSGEO4W_ROOT%\apps%QGISNAME%
set QGIS_PREFIX_PATH=%QGIS%
CALL "%OSGEO4W_ROOT%\bin\o4w_env.bat"
REM Python Setup
set PATH=%OSGEO4W_ROOT%\bin;%QGIS%\bin;%PATH%
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python39
set PYTHONPATH=%QGIS%\python;%PYTHONPATH%
ECHO OSGeo path is: %OSGEO4W_ROOT%
ECHO Getting QGIS libs from: %QGIS%
ECHO Python loaded from: %PYTHONHOME%
C:\OSGeo4W\bin\python-qgis-ltr.bat C:\Users\Shadow\Desktop\PyQgis\Intersection.py %*
Intersection.py looks like this:
from qgis.core import *
import qgis.utils
import glob
i=0
print("start")
gemeinden = r"C:\Users\Shadow\Desktop\PyQgis\Gemeinden"
potenzial = r"C:\Users\Shadow\Desktop\PyQgis\Shape-files"
shp_files = glob.glob(gemeinden+"\*.shp")
for file in shp_files:
i += 1
#if i <= 53:
# pass
#else:
print(str(i)+","+str(len(shp_files))+"()"+file[:-4][41:])
output = r"C:\Users\Shadow\Desktop\PyQgis\Gemeinden\"+file[:-4][41:]+".shp"
ergebnis = processing.run('saga:intersect', {'A':file, 'B':potenzial, 'RESULT':output})
The Error:
NameError: name 'processing' is not defined
Everything works fine when I start the script inside the QGIS Python-console.
Do I have to import some modules inside the Intersection.py or are some environments missing in the PyQgis.bat?