3

I am novice mapper. I ran into some trouble with QGIS today when trying to add additional census tracts to a layer filter.

The tract exists within the layer I'm filtering, but there seems to be a hard cap of 30 for number of times I can use the OR statement in the filter. I've rearranged the tracts and flipped which ones I am using, but can never get past 30 selections. For reference, my filter query that I ended up with is below: to replicate, use the Census Bureau tract map of Michigan.

"COUNTYFP" = '077'  AND ("NAME" =  '1' OR "NAME" = '10' OR "NAME" = '11' OR "NAME" = '12' OR "NAME" = '2.01' OR "NAME" = '2.02' OR "NAME" = '3' OR "NAME" = '5' OR "NAME" = '6' OR "NAME" = '9' OR "NAME" = '15.01' OR "NAME" = '15.02' OR "NAME" = '15.03' OR "NAME" = '15.04' OR "NAME" = '15.06' OR "NAME" = '15.07' OR "NAME" = '16.01' OR "NAME" = '16.03' OR "NAME" = '16.04' OR "NAME" = '17.01' OR "NAME" = '17.02' OR "NAME" = '18.01' OR "NAME" = '18.02' OR "NAME" = '18.03' OR "NAME" = '29.03' OR "NAME" = '29.04' OR "NAME" = '29.05' OR "NAME" = '30.04' OR "NAME" = '55.01' OR "NAME" = '55.02')
  • 2
    Try using something like "COUNTYFP" = '077' AND ("NAME" IN ('1', '10', '11', '12'... etc). Will that let you add more than 30 values from the name field? At the very least it will save you from typing "NAME" 30 times. – lambertj Oct 2 at 17:10
  • 1
    If @lambertj 's suggestion doesn't solve it, add a new field, "filter". Use the Field Calculator to fill the field with the values 0 or 1, using the filter expression you tried to use. If the 30 value limit still applies here, run the Field Calculator more than once, with an expression like if( [filter expression], 1, "filter"), which should add 1s to features that meet the conditional statement but not change the current value for other features. When all the features you want to see have "filter" = 1, use that in the filter query builder. – csk Oct 2 at 18:58
2

Using IN instead of stringing together "NAME" = x OR "NAME" = y statements will let you select more than 30 values.

The example below uses counties, but selecting your census tracts by attribute will work the same way if you structure your query like this:

"Shape_Length" > 20 AND  ("CO_FIPS" IN (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 47, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69))

So in your case, you would replace the fields above with the ones you were interested in:

"COUNTYFP" = '077' AND ("NAME" IN (1, 10, 11, 12, 2.01))

Add all the values of NAME you want to select inside the IN statement, separated by commas. Whether the values of NAME need to be in quotes or not depends on if the field is a number or text.

enter image description here

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.