2

I'm building a script in the graphical modeler. I have different inputs that I have to give and one is optional. I'm trying to build a conditional branch that check the presence or absence of the optional input. But I can't find an expression for that.

Any idea?

5
  • Is this what you are looking for ? gis.stackexchange.com/questions/383404/…
    – Kalak
    Commented Mar 30, 2022 at 7:06
  • As per the help center please do not include chit chat like thanks within your posts.
    – PolyGeo
    Commented Mar 30, 2022 at 7:13
  • qgis.org/en/site/forusers/visualchangelog314/…
    – Kalak
    Commented Mar 30, 2022 at 7:14
  • Yes, I use conditional branch. But my question is what expression I can use to test if my layer input2, which is optional, is given in the model? For exemple, in the conditional branch, the expression would be layer_exist(@input2). But the expression layer_exist doesn't exist... So is it a way to do that?
    – katagena
    Commented Mar 30, 2022 at 9:44
  • i think there is something broken or i am doing something wrong
    – Kalak
    Commented Mar 30, 2022 at 11:21

2 Answers 2

3

I found myself. It's simple as I thought. I just use a conditional branch with @input2 IS NOT NULL, and the other one with @input2 IS NULL.

1
0

I am pretty sure something is broken (btw QGIS 3.16.11)

I have a model with:

  • a Vector Layer input named 'test'
  • a print warning using the following expression if(parameter('test'), 'TRUE', 'FALSE')
  • a conditional branch with:
    • true_branch with expression if(parameter('test'), True, False)
    • false_branch with expression if(parameter('test'), False, True)

When I run the model twice (once without layer passed to it and once with) I get the following where the warning is working fine but the conditional branch fails enter image description here

3
  • I don’t understand your true_branch and false_branche? In evercase, the value will be true and false (case you add the layer) or false and true (case you don’t add the layer! So it will always trigger both branches? Or I ‘m wrong?
    – katagena
    Commented Mar 30, 2022 at 12:16
  • Plus, you write if(parameter(test), true, false)… but if parameter(test) is what? Not NULL?
    – katagena
    Commented Mar 30, 2022 at 12:19
  • parameter('test') return the value inside the 'input parameters' dictionnary you can see on the picture. The conditions are simple if parameter('test') == True than the true branch should be active and the other one inactive and the opposite when parameter('test') == False, basically I was trying to make a if else with the conditional branch system
    – Kalak
    Commented Mar 30, 2022 at 12:32

Your Answer

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

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