9

If I define a Vector Layer as an input parameter to a QGIS model, then the parameter name is exposed as a variable in a Field Calculator within the model, however I am unable to use this variable as I am not sure what data type it is. For example with a Vector Layer parameter of InData, I have tried evaluating the following expressions into a text field in a temporary layer:

@InData => ''

layer_properties(@InData, 'name') => NULL

layer_properties(@InData, 'id') => NULL

parameter( 'InData') => NULL

This is the model:

model

Variables exposed in Field Calculator (the expression doesn't seem to be case sensitive):

variables

My question is - how do you use the @indata variable? For example, can I use it to extract the CRS of the input layer?

A workaround is to use one of the @layer / @layer_id variables in a field calculator as the first tool connected to the input in the model, but then the result will need to be stored as an attribute if it is needed later in the model (see How to access input layer properties from QGIS' Modeler?).

2

You can use layer_property function with @layer keyword. @layer returns input layer itself.

Normally, the first parameter of layer_property is a string representing layer name or ID. But in Modeler case, since you cannot know the name of layer passed as input, it's useless. Therefore, the other choice is to use @layer keyword instead of layer name.

layer_property(@layer, 'id') 
layer_property(@layer, 'crs')
...
| improve this answer | |

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.