3

I have a point layer, consisting of 12 points with fid 1 to 12. I want to render points with fid > median (fid) - thus in this case, point 7 to 12. That works perfectly if using geometry generator with this expression - see screenshot, where only 7 to 12 are rendered, whereas 1 to 6 only have labels/callouts:

if ( 
    "point_id" > median (
        "point_id"
    ), 
    $geometry , 
    ''
)

enter image description here

However, when I use the same expression with Menu Processing / Toolbox /Geometry by expression on the same point layer, I get an error: Cannot use relation aggregate function in this context. Why is that - or asked the other way round: how to correct the expression? It's the same expression as in geometry generator in rather the same context.

I am asking specifically about this relation aggregate function error, as I already encountered it several times in more complex cases. In this simple case, of course there would be easier ways to achieve the goal. However, I wanted to present a simple case to make the error easier to reproduce.

1 Answer 1

5

When using aggregate functions with processing it seems there is a scope problem.

For your problem, you should use the aggregate function and refer to the layername of your source point layer.

Something like that :

if (

    "point_id" > aggregate('<layername>','median', "point_id"), 
    $geometry , 
    geom_from_wkt('POINT EMPTY')
)

You need also to create a valid geometry point with geom_from_wkt('POINT EMPTY')

1
  • OK, works perfectly! It really seems that not only aggregate functions behave different in geometry generator and Geometry by expression tool, but empty outputs as well: in Geometry by expression, indeed only geom_from_wkt('POINT EMPTY') works, whereas in geometry generator, an empty output '' works well.
    – Babel
    Commented Jan 18, 2021 at 20:53

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.