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:
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.
When I test the expression I use for the filter as a standalone expression, it returns 9, as expected.
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
)
)
What am I missing?
1 Answer 1
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]
)
-
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 returns9
as expected.Matt– Matt2022年12月07日 08:07:58 +00:00Commented Dec 7, 2022 at 8:07 -
Ok, very strange behavior of this expression.Mayo– Mayo2022年12月07日 12:58:53 +00:00Commented 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– Mayo2022年12月07日 17:50:44 +00:00Commented Dec 7, 2022 at 17:50
-
Good idea to check. It's the expected array (using
[0]
gets the first pointid=0
).Matt– Matt2022年12月07日 18:38:24 +00:00Commented Dec 7, 2022 at 18:38 -
So the problem is clearly the filter.Mayo– Mayo2022年12月07日 18:40:47 +00:00Commented Dec 7, 2022 at 18:40
Explore related questions
See similar questions with these tags.