How can I get the layer name or layer id of the result of an processing algorithm within QGIS graphical modeler, so I can use aggregate() function in a later processing step? Is this somehow possible at all?

aggregate( @layer_name,'collect',$geometry) cannot work here because @layer_name is not related to a specific processing algorithm output. If I try aggregate( @name_of_processing_step_OUTPUT,'collect',$geometry) or aggregate(layer_property( @name_of_processing_step_OUTPUT,'id'),'collect',$geometry) I get Cannot find layer with name or ID '' in preview and just no output when running the model.


1 Answer 1


What you intend to do is now possible using the variables that QGIS creates when you add an algorithm to the model in newer QGIS versions. You can now use the variable from a previous processing step, such as @name_of_processing_step_OUTPUT:


In your case, the output of Feature Filter is a layer and to use it in the expression with aggregate(), you have to get the layer's name. For this, use the function layer_property().

I created a simple model based on your's: it takes an input (point layer with 100 features), then in the model uses Feature Filter to filter $id < 50 and then only for the filtered features (=algorithm output) creates a new string (text) field id_new with the aggregated id values (just for demonstration purpose).

To do so, in the field calculator algorithm, I set the Input layer to Algorithm Output and use the output from algorithm "Feature Filter". The expression to use looks like this:

array_to_string (
    aggregate (
        layer_property (@Feature_filter_OUTPUT_, 'name'),

Model's Field Calculator Algorithm dialog window: enter image description here

The Model and attribute tables of input and resulting output layers: after running the model, only the first 49 features ($id<50) are kept and the field id_new with aggregated id values is added: enter image description here

  • @MrXsquared what makes you sure this solution works since 3.26? I tested it with 3.24 and it works. I don't have older QGIS versions at hand, but I can't find any information in QGIS visual changelogs for versions 3.22 + that shows that this was introduced: qgis.org/en/site/forusers/visualchangelogs.html. So probably it was possible even before.
    – Babel
    Oct 29, 2023 at 14:20
  • Nothing. Just the comment on your linked answer. I was too lazy to test myself or search for changelogs. But definitely it did not work on older versions back in 2020. If it would have worked why did I ask the question then ;)
    – MrXsquared
    Oct 29, 2023 at 15:36
  • I ask because in your question, you have a variable @name_of_processing_step_OUTPUT - so I wonder what this should have been good for if not accessing temporary layers...
    – Babel
    Oct 29, 2023 at 16:00

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.