5

I am trying to use field calculator within a model. In this formula I want to reference the output (temporary layer) of another step of the same model (output objektfilter_strassen_wege, which is named strassenpolygone_flurstuecke). Since this layer is not loaded in QGIS, I get no result. If I save the correct layer after running through the model and have the model repeated, I get a result. But that's not my goal! I want to get it the first time. I enter the following into the field calculator:

aggregate(
 layer:= 'strassenpolygone_flurstuecke',
 aggregate:='concatenate',
 expression:=oid,
 concatenator:=', ',
 filter:=intersects($geometry, geometry(@parent))
 )

strassenpolygone_flurstuecke should be called differently as input, I suspect. So not layer:= but something else that suggests that it is a generated output. The second possibility that went through my head was to choose to save the layer strassenpolygone_flurstuecke instead of the temporary layer. But even if I do this using the model, I don't get any result.


1
  • Have tried this kind of calculations within graphical modeler a lot, but never made it work. A similar question about this is still unanswered. I am afraid the answer is "not possible", but lets hope for the best.
    – MrXsquared
    Nov 18, 2020 at 13:09

3 Answers 3

6

This is currently (QGIS 3.16.1) not possible, see the following comment from https://github.com/qgis/QGIS/issues/30397#issuecomment-505699624 :

The issue here is that expression functions which operate on map layers [...] 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.

Here is another ticket describing your use case which is marked as a duplicate of the ticket linked above: https://github.com/qgis/QGIS/issues/37347

2
  • Hello pathmapper, thanks for your answer. Unfortunately, I am not looking for an input layer which is an output of another step but for the layer in my formula within the field calculator. The field calculator is part of my geaphical model.
    – Alice123
    Nov 25, 2020 at 13:48
  • @Alice123 thanks for your reply. Unfortunately this is currently not possible, see my adapted answer above.
    – pathmapper
    Nov 26, 2020 at 8:28
3

You definitely can reference a (temporary) output of an algorithm in a QGIS model in an expression. When you add an algorithm to the model, QGIS automatically create new variables for the output of that algorithm. You can find these variables listed wherever you have the expression string builder inside the model.

The variables are named like the algorithm with the suffix _OUTPUT_ and the leading @ that marks a variable, e.g. @Feature_filter_OUTPUT_:

enter image description here

5
  • I wonder why you have an underscore here in the end of the variable name. In my case it is always algorithm_name_OUTPUT.
    – winnewoerp
    Oct 29, 2023 at 3:05
  • 1
    Is this possibly a version issue? In my case (still 3.22.7) using the [...]_OUTPUT variable in the expression leads to an error. Also, if it has been resolved in a recent release, why is the issue still marked as open here github.com/qgis/QGIS/issues/30397?
    – winnewoerp
    Oct 29, 2023 at 3:08
  • 2
    Seems to work with 3.26.X or newer!
    – winnewoerp
    Oct 29, 2023 at 3:44
  • The variable appears like this with underscore at the end, I don't know why
    – Babel
    Oct 29, 2023 at 7:53
  • 1
    Maybe we should always mention QGIS versions when referencing this issue, to make clear that it only works with newer versions? You could add that to your answer. In 3.22 it definitely did not work, but as you mentioned in the first comment here gis.stackexchange.com/a/469259/52808, starting at 3.24 it obviously does.
    – winnewoerp
    Oct 30, 2023 at 5:34
-1

I came across this post while looking for a solution to a similar problem. You just had to replace the layer name with @layer.

aggregate(
 layer:= @layer,
 aggregate:='concatenate',
 expression:=oid,
 concatenator:=', ',
 filter:=intersects($geometry, geometry(@parent))
 )
1
  • 1
    I have a strong feeling this is not an accurate answer. This seems to be assumed to work by the answerer because it works outside the model situation. But since all linked issues concerning this on the official github are still open it is clearly not "fixed".
    – Kalak
    Oct 19, 2023 at 7:48

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.