1

I'm having a bit of trouble using "Select by expression" in QGIS.

I'm working on a shapefile of a polyline network, each line has a unique reference which is made up of letters, numbers and symbols such as 'CRCCU50234/50010'.

I often have to select lines(aka sections) based on a list of references so i've created a simple tool in excel to build a query to select by expression based on two inputs; a field and a value. The expression built looks like;

"Section_Re" = 'CRU50229/50010' OR 
"Section_Re" = 'CRCC0229/50020' OR 
"Section_Re" = 'CRCCU50229/50030' OR 
"Section_Re" = 'CRCCU50230/50005' OR 
"Section_Re" = 'CRCCU502/50011' OR 
"Section_Re" = 'CRCCU501/50005' OR 
"Section_Re" = 'CRCCU0232/010'

where "Section_Re" is the field name and the values in single quotes are the unique references.

I've been using this method of selecting sections based on a list for about 8 months now on multiple shapefiles without issue. A couple of days ago, this stopped working when used on any selection greater than about 10 records.

Strangely, the expression returns nothing when ran in full (for about 300 sections) but will return results if all but ~10 lines are removed from the expression. It's an OR expression so i would expect that even if some of the lines didn't return a result, those that did would be selected.

I'm very confused as to what's going on so I thought i'd turn to the stack exchange community for help. I hope that i've given enough information and explained my issue clearly, but if anything else is required, please let me know.

  • 4
    Could try to use this expression: "Section_Re" in ('CRU50229/50010', 'CRCC0229/50020', 'CRCCU50229/50030', 'CRCCU50230/50005', 'CRCCU502/50011', 'CRCCU501/50005', 'CRCCU0232/010')? You can append any value after that. – ahmadhanb Jan 28 at 12:29
  • I've had expressions produce complete failure in the past, although for me it was when using rule-based styling, when I made one tiny mistake in the expression - for example a missing speech mark -> ' The failure was a silent one - simply producing no results. It may be worth an even more careful check for such errors, or indeed trying ahmadhanb's suggestion. – Rostranimin Jan 28 at 15:13
0

Please make sure that your data does not have any extra space. If yes, you will need to trim them.

After, please use this expression instead : "Section_Re" in ('CRU50229/50010', 'CRCC0229/50020', 'CRCCU50229/50030', 'CRCCU50230/50005', 'CRCCU502/50011', 'CRCCU501/50005', 'CRCCU0232/010')

it's always good to load your data in the tool (before runing the selection, as shown below)

enter image description here

Hope this help :)

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.