The solution (principle)
Inside a filter, you can't include further complex expressions. So you have to stick the expression togeteher using eval()
function to first create the value of your 2nd expression and then stick the output of this together with a string to create a text string representing the final expression. Then use eval()
to actually "run" the expression.
It works like this pattern (see at the bottom of this solution for a more detailed explanation):
eval ('my string 1' || my expression || 'my string 2')
Step by step
Create your desired output with the second expression you provided: lines 5 to 13 in my expression.
Stick this together with a string (strings work inside single quotes: '
) that provide the code from your first expression - in my case lines 2 to 4 and 2nd last line. Connect the three elements with pipes: ||
. Be aware how to use quotes (see at the bottom for details)!
Inclose everything in an eval()
function: it converts the text (string) sticked together in step 2 to an expression that is evaluated and outputs the desired result:
eval (
'aggregate(
..., -- everything here that is normally in single quotes ' must be in two single quotes: ''
filter:="observatoire_uuid" = ' ||
aggregate(
'observatoire_626e5cbe_01f8_4abf_a445_98e78c6b4dae',
'min',
"uuid",
distance(
$geometry,
geometry(@parent)
) < 50
) ||
')'
)
Be aware of
Make sure to get all quotes correctly, otherwise it will not work:
- single qutotes:
'
- two repeated single quotes
''
: everywhere where in your expression you have the three points ...
as placeholders (line 3 above), you should double single quotes by another single quote to mask it.
- double quotes
"
Explanation of the pattern shown above
Inside eval()
you stick together two strings with an expression. The expression is your 2nd expresion, strings 1 and 2 are your 1st expression, split up after the equal sign =
. So you have aggregate ( ... =
(first part of your 1st string) enclosed in single quotes to make it a string. Everything inside this string that initially has single quotes must be written with two single quotes. The second element sticked together is the output of the epxreesion: '{54ab58ff-aefc-495d-88af-83ded1742df3}'
. At the end, add a closing bracket ')'
, again as a string (my string 2
).