简体   繁体   中英

PyQGIS: Select by more than one expression

I'd like to select features via PyQGIS using the SelectByFeature-function. It only seems to work for one expression though. I tried linking expression with "and" or "+" but that doesn't work. Anybody who can help?

Most likely, you are getting your syntax wrongly formatted.

Depending on where you are executing your expressions, the syntax should work the same. You can select with more than one expression by using " and " and " or " operators as demonstrated below where two values are being selected from two different columns.

The general expression look like this:-

"col1"  = 'value1' and  "col2" = 'value2'

Processing algorithm expression will look like this:-

processing.run("qgis:selectbyexpression", {'INPUT':'C:/Users/home_pc/Desktop/state_polygon.shp','EXPRESSION':' \"col1\"  = \'value1\' and  \"col2\" = \'value2\'','METHOD':0})

This page has more useful information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM