I Have 2 Layers:

enter image description here

I want to Filter Layer 2 by an attribute from Layer1 for some rule based styles. I'm currently using following expression to realize that:

"C1" = attribute(get_feature(‘Layer 1', 'ID', '1'), 'C') or "C2" = attribute(get_feature(‘Layer 1', 'ID', '1'), 'C') or "C3" = attribute(get_feature(‘Layer 1', 'ID', '1'), 'C')… etc.

It does its job, but due to the amount of features (a few thousands), performance is quite bad.

So I made a new field called "CG" in Layer 2 using following expression in field calculator:

"C1" + ' '+ "C2" +' '+ "C3" +' '+ "C4" +' '+ "C5"… etc.

The Field “CG” I can filter using eg. “CG” ILIKE “%C1 %”

Question: How can I now combine the attribute(get_feature()) and ILIKE expression to Filter the Field “CG” in Layer2 by an attribute of Layer 1 in Field “C” ? An example would be awesome.


I finally was able to solve my Problem.

Answer: "CG" ILIKE '%'+ attribute(get_feature('Layer 1', 'ID', '1'),'C') +' %'

(space in front of last %)

But it required to add in Field “CG” additional spaces in front of C1 and after C15. For this I used following Expression in the field calculator for the Field “CG”:

‘ ‘+ "C1" + ' '+ "C2" +' '+ "C3" +' '+ "C4" +' '+ "C5" +’ ‘+ … “C15” +’ ‘

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.