I'm trying to run a Python script from OSGeo4W Shell. Im doing this by typing "python-qgis C:\path\test.py"
Everything seems to go fine until the script launches the processing module. After that console gives me a lot of invalid escape sequence warnings.
Then when the script hits the SQL- algorithm it fails to find the referenced table. It still manages to load it.
ERROR: Referenced table file in query not found
Here is my script:
import sys
from qgis.core import (
QgsApplication,
QgsProcessingFeedback,
QgsVectorLayer,
QgsCoordinateReferenceSystem,
QgsProcessingParameterFeatureSource,
QgsProcessingFeedback
)
QGIS = 'C:\\Program Files\\QGIS 3.6\\apps\\qgis'
# Prefix
QgsApplication.setPrefixPath(('QGIS'),True)
qgs = QgsApplication([], False)
qgs.initQgis()
# Processing path
sys.path.append('C:\\Program Files\\QGIS 3.6\\apps\\qgis\\python\\')
sys.path.append('C:\\Program Files\\QGIS 3.6\\apps\\qgis\\python\\plugins')
path = 'O:\\Desktop\\Qgis\\File\\file.shp'
IN = QgsVectorLayer(path,'file','ogr')
if IN.isValid():
print ('Success!')
else:
print ('Failed!')
OUT = 'O:\\Desktop\\Area\\Leik\\A_Area.shp'
from qgis.analysis import QgsNativeAlgorithms
import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
AO = {
'INPUT_DATASOURCES': IN,
'INPUT_GEOMETRY_CRS': QgsCoordinateReferenceSystem('EPSG:3883'),
'INPUT_GEOMETRY_FIELD': '',
'INPUT_GEOMETRY_TYPE': None,
'INPUT_QUERY': 'SELECT \"file\".* \nFROM \"file\"\nWHERE \"file\".\"type\" like \"a%\"',
'INPUT_UID_FIELD': '',
'OUTPUT': OUT,
}
feedback = QgsProcessingFeedback()
result = processing.run('qgis:executesql', AO,feedback=feedback)
print(result)
sys.exit()