3

I have a point layer with one field, id ranging from 0 to 9. I have a polygon that intersects some of the points, like so:

enter image description here

My aim is to use an expression to get the intersecting point with the highest value for id.

For demonstration purposes I use a Geometry Generator symbol layer on my polygon layer.

collect_geometries(
    overlay_intersects(
        'point_layer', 
        $geometry,
        filter:= id = array_max(overlay_intersects('point_layer', id))
    )
)

I expect there to be a single point at the location of the point in point_layer with the highest id (9). However, all intersecting points are returned.

enter image description here

When I test the expression I use for the filter as a standalone expression, it returns 9, as expected.

enter image description here

And when I hard-code the highest id value (9), I get the desired result:

collect_geometries(
    overlay_intersects(
        'point_layer', 
        $geometry,
        filter:= id = 9
    )
)

enter image description here

What am I missing?

1 Answer 1

5

Not a very elegant way, but I think it will work.

with_variable(
    'maxval',
    array_max(
        overlay_intersects(
            'point_layer', 
            "id"
        )
    ),
    array_filter(
        overlay_intersects(
            'point_layer', 
            array("id", $geometry)
        ),
        @element[0] = @maxval
    )[0][1]
)
7
  • This seems like it should work, indeed. However, it is returning NULL. (Without the [0] array index it returns an empty array). That seems strange. Evaluating @maxval without the second overlay expression returns 9 as expected.
    – Matt
    Commented Dec 7, 2022 at 8:07
  • Ok, very strange behavior of this expression.
    – Mayo
    Commented Dec 7, 2022 at 12:58
  • Just for debug, remove the filter from the second overlay. To see if it still return an empty array.
    – Mayo
    Commented Dec 7, 2022 at 17:50
  • Good idea to check. It's the expected array (using [0] gets the first point id=0).
    – Matt
    Commented Dec 7, 2022 at 18:38
  • So the problem is clearly the filter.
    – Mayo
    Commented Dec 7, 2022 at 18:40

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.