[GIS] How to Unselect Features with QGIS tool “selectbyexpression’ and the “>” Operator

pythonqgis

First of all I've successfully used the "selectbyexpression" tool to UN-SELECT points by setting its 3rd parameter to "2" in the following script:

Input = QgsMapLayerRegistry.instance().mapLayersByName('Central_Region_civic_pts')[0]
clear_expression = '"STRNAME" = '+"'"+"Main"+"'"
processing.runalg('qgis:selectbyexpression', Input, clear_expression, 2)

But now I want to write an expression that will unselect EVERYTHING, not just a particular street by name (e.g. "MAIN"). This will be useful near the start of my script to wipe the slate clean, just in case anything is already selected, before my script goes on to make the selections I actually want.

Since my 'Input' file has a "PID" column ("Property ID", all numbers) I figured something like the following would work:

clear_expression = '"PID" > 0'

But it doesn't.


QUESTION

I suspect the problem is with the ">" symbol. Can anyone confirm this, and suggest a workaround or another tool to do the job?


I also suspect there's nothing unique about the ">" symbol. I'll bet there are more operator symbols than ">" that also don't work with this tool because the "Select By Expression" GUI at the top menu of QGIS only has 9 operator options at the top and ">" isn't one of them. Neither is "<". And there's no option for "does not equal" either, etc, etc…

enter image description here

Best Answer

How about this, where Input is your layer object?

Input.removeSelection()

see: How to remove all selection from all registered layers using QGIS plugin?