3

The setting

In a QGIS model, I have an input layer polygon from which a grid is cretated.

On this grid-layer, a new attribute field should be created based on an expression that refers to the input layer polygon. That works well as long as I set a fixed name for the layer polygon - see the expression and the model linked here (at the bottom).

Basically, I just have to replace 'polygon' in the overlay_intersects-part of the expression in a way to refer to the model's input layer: overlay_intersects('polygon',$geometry) works, as long as the layer indeed is named 'polygon', but the model should be flexible to take the selected input layer here.

The question

How can the layer-name be defined so that it refers to the name of the input layer, regardless of how it's name is?

What I tried

In the field-calculator dialog, I select pre-defined value and try to set my expression in 'single quotes' as described here in the style of: 'expression' || @loadpolygonlayer || 'expression'. For the layer to refer, I select it from the context variables as can be seen on the screenshot.

I also tried to get the name of the layer by using this syntax and different variations with and without quotes, with masking single quotes etc., with no success.

enter image description here

2
  • This is (currently) not possible. See github.com/qgis/QGIS/issues/37347 which is marked as duplicate of github.com/qgis/QGIS/issues/30397. Where nyalldawson states The issue here is that expression functions which operate on map layers (including get_feature_by_id ) don't currently have access to any temporary output layers created a step in a model. This applies to a lot of functions, including aggregates. – MrXsquared May 25 at 16:34
  • I stumbled upon this when I looked for a solution. However, I'm not sure that this is the same case: in fact, I want to refer to an already existing layer (not a temporary one, not one created as model-output), the same as the input layer. There is even a variable appearing in the selection as can be seen on the screenshot. So it should be possible to use this somehow? Fact that the model works when refering to the exact layer-name makes me optimistic that it should be possible. – Babel May 25 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.