As per https://docs.qgis.org/3.22/en/docs/user_manual/processing/standalone.html?highlight=qgis_process I am trying to run the following (that works in the QGIS python console).
alg_params = {
'EXPRESSION': '"Speed KmH" < '+ str(max_speed) ,
'INPUT': in_file,
'OUTPUT': 'd:/scratch/1.tab',
}
outputs['ExtractByExpression']=processing.run('native:extractbyexpression', alg_params)
When I run the following in OSGEO Shell I get
C:\OSGeo4W\apps\qgis\bin>qgis_process run qgis:extractbyexpression -- INPUT=d:\scratch1円.csv OUTPUT=D:\scratch1円.tab EXPRESSION="FID"<30
C:\OSGeo4W\apps\qgis\bin>qgis_process run qgis:extractbyexpression -- INPUT=d:\scratch1円.csv OUTPUT=D:\scratch1円.tab Traceback (most recent call last):
Problem with OTB installation: OTB folder is not set.
---------------- Inputs
---------------- INPUT: d:\scratch1円.csv
OUTPUT: D:\scratch1円.tab
ERROR: The following mandatory parameters were not specified
EXPRESSION: Expression
C:\OSGeo4W\apps\qgis\bin>
How do I structure the expression? I have tried it in single quotes and double quotes. It accepts the input/output when we use = rather than : but I just can't get even a simple expression to work.
1 Answer 1
You will need to wrap the expression in double quotes, because the <
character is a reserved character within the windows command line used for redirecting inputs/outputs.
The following command works for me using QGIS 3.22:
qgis_process-qgis-ltr run qgis:extractbyexpression -- INPUT=D:\Downloads1円.shp OUTPUT=D:\Downloads1円.tab EXPRESSION=""FID"<30"
> ----------------
> Inputs
> ----------------
> EXPRESSION: FID<30
> INPUT: D:\Downloads1円.shp
> OUTPUT: D:\Downloads1円.tab
>
>
> Warning 6: driver MapInfo File does not support creation option BLOCK_SIZE
> 0...10..
> ----------------
> Results
> ----------------
>
> OUTPUT: D:\Downloads1円.tab
Some additional notes:
- my command uses
qgis_process-qgis-ltr
because I ran on the standalone version of QGIS. With your installation through OSGeo keep usingqgis_process
- if the file paths of input or output contain any spaces (or reserved characters such as & , | , ( , ) , < , > , ^), you also need to wrap the path with double quotes e.g.
INPUT="D:\Test Data1円.shp"