When putting together an answer for this question, I attempted to use the @layer_name variable in an aggregate function to make the expression more generic and easier to use when running the "Geometry by expression" tool as a batch process over multiple layers.
The full expression I was trying to use is:
scale( geometry:=$geometry, x_scale:=4, y_scale:=4, center:=centroid( aggregate(layer:=@layer_name, aggregate:='collect', expression:=@geometry) ) ) However, when I run the tool with that expression, the processing log shows the following error which I assume is because the @layer_name variable is empty:
Algorithm 'Geometry by expression' starting… Input parameters: { 'EXPRESSION' : "scale(\n geometry:=$geometry, \n x_scale:=4, \n y_scale:=4, \n center:=centroid(\n\taggregate(layer:=@layer_name, aggregate:='collect', expression:=@geometry)\n )\n)", 'INPUT' : '/path/to/small.shp', 'OUTPUT' : 'TEMPORARY_OUTPUT', 'OUTPUT_GEOMETRY' : 0, 'WITH_M' : False, 'WITH_Z' : False } Evaluation error: Cannot find layer with name or ID '' Execution failed after 0.04 seconds In the screenshot below are the parameters I set for the tool and you can see that the @layer_name variable is populated in the function/variable selector description on the right.
How can I avoid hardcoding the layer name in this expression so the tool can be batched and applied to multiple input layers?
