0

I am using QGIS 3.10 to make simple queries using the "Filter" and "Select by Expression" tools. I have a layer with cities/towns in New York State with population attributes, e.g. "POP1990" is population in 1990, "POP2010" is population in 2010, etc.

Certain queries seem to work in one tool but not the other. For example, I want to select all towns/cities in New York State where the population increased by more than 5% from 1990 to 2010. Oddly (to me) when I make all references to an attribute/field name lowercase, the "Select by Expression" tool works, but when I spell the attribute/field name with the correct case and put it in double quotes it does not work.

Below are the expressions I write, the tool I use, and the outcome:

Tool: "Select by Expression"
Expression: ( "POP1990" * 1.05 ) < "POP2010"
Outcome: doesn't work - selects all features

Tool: "Filter"
Expression: ( "POP1990" * 1.05 ) < "POP2010"
Outcome: doesn't work - all features remain

Tool: "Select by Expression"
Expression: ( pop1990 * 1.05 ) < pop2010
Outcome: WORKS CORRECTLY - 469 out of 994 features selected

Tool: "Filter"
Expression: ( pop1990 * 1.05 ) < pop2010
Outcome: doesn't work - all features remain

I could give other examples of different expressions working or not working.

Data are downloadable below as a link, if you would like to test it yourself. (This is my first Stack Exchange post, by the way.)

Here is the New York State cities/towns shapefile layer for download.

3
  • don't no why, but it seems to be a bug. to_int(( "POP1990" * 1.05 )) < "POP2010" or ( "POP1990" * 1.05 )) < to_real("POP2010") works. so comparing integers to real does not work properly... – eurojam Mar 1 at 21:01
  • One possible reason is from the way these query are interpreted. A filter query is read and interpreted by the data provider and should be written according to the specific provider syntax while all other expression (including select by expression) are interpreted by QGIS and should follow QGIS syntax. this could be a better explanation : gis.stackexchange.com/questions/212393/… – J.R Mar 2 at 18:26
  • Thanks so much for the help. – Stephen Tulowiecki Mar 8 at 16:15
0

Try using a more recent version of QGIS. I vaguely recall that issues with comparing real/integer fields was fixed somewhere around QGIS 3.14. There used to be issues with integer division using OGR in 3.12 which might have been related.

I tested out all your queries/tools on QGIS 3.16.3 and all of them returned 469 results.

1
  • Thanks so much for the help. Installing QGIS 3.16 fixed the problem. – Stephen Tulowiecki Mar 8 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.