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:
Variables exposed in Field Calculator (the expression doesn't seem to be case sensitive):
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?).
-
1This seems related to github.com/qgis/QGIS/issues/39119#issuecomment-768642727 , I too was wondering how to get the CRS of a layer. :(bugmenot123– bugmenot1232021年11月04日 14:33:25 +00:00Commented Nov 4, 2021 at 14:33
1 Answer 1
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')
...
-
1Hi Kadir, this is what I was getting at in my last paragraph, however this approach is limited (or was when I wrote the question) to the first tool of the model as after that the layer variable is updated and no longer refers to the input dataset.Andy Harfoot– Andy Harfoot2021年02月15日 16:36:04 +00:00Commented Feb 15, 2021 at 16:36