I am using the Graphical Modeler in QGIS for the first time, and would like to filter a very large point layer of postcodes in the UK by the first letter of the postcode (for now 'B') before doing a 'Join Attributes by Location' with a polygon layer (the idea is to then repeat this for all letters and create separate output files).

However, I am not able to get the LIKE statement to work. The below StackExchange question suggests this may be due to the 'Features' not being found by the dialogue, yet I don't know how to resolve this, since the features are supposed to be taken from the Input layer (I tried setting 'Input layer' both as a 'Value' and 'Model Input' (and then adding a corresponding vector input)) when I run the model.

QGIS query syntax differs between attribute table and feature filter

I have tried the expressions

"pcd" LIKE 'B%' 

SELECT * FROM 'NSPL_FEB_2022_UK_ALL_PART1' WHERE "pcd" LIKE 'B%' (and variations of this)

... although I don't think I am on the right track.

To be clear, I am able to use "pcd" LIKE 'B%' to filter the point layer on right click --> Filter... without issues, and the spatial join is working without issues as well. I didn't really find any helpful documentation either.

Would anyone be able to help?

Screenshot below:

enter image description here

  • "pcd" LIKE 'B%' looks correct. Just tried it in a model in 3.24 and it works just fine. Is it possible for you to share your setup?
    – MrXsquared
    Apr 30, 2022 at 22:57
  • Thank you for your comment! What precisely do you mean with setup? I am using QGIS 3.22. Just wondering, did you do it in the Graphical Modeler and did it actually give you the right output? I've been trying for quite a few hours, I am pretty sure everything works fine on my side, the trouble only starts when I try doing it within the Graphical Modeler!
    – Arnold K
    Apr 30, 2022 at 23:02
  • The model and a sample of your data. Yes, I tried it in modeler and it gives the correct output. Works in 3.22.4 as well.
    – MrXsquared
    Apr 30, 2022 at 23:34
  • What do you mean when you say "... I am not able to get the LIKE statement to work"? Do you get an error statement, or the wrong results, or...?
    – Stu Smith
    May 1, 2022 at 6:35
  • 1
    @MrXsquared Thank you, I rebuilt everything from the beginning and it did indeed work now. I think I was confused because I thought setting the 'Feature filter' as an input of the 'Join Attributes by Location' would mean that the fomer runs before the latter but this isn't the case, so the spatial join happened before the features were filtered. Anyway - thank you very much for your help!
    – Arnold K
    May 4, 2022 at 7:51


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.