2

I'm facing an issue while trying to calculate the maximum value within polygons from another vector layer in QGIS. I've tried using the aggregate function with the 'max' statistic, but the result is always null.

Here's the expression I'm using:

aggregate(
layer:= 'Layer1',
aggregate:='max',
expression:=WLevelMax,
filter:=intersects($geometry, geometry(@parent))
)

I've made sure that the layer names and field names are correct. The strange thing is that when I remove the intersects($geometry, geometry(@parent)) condition, the command works, but I want to ensure the calculation is based only on the polygons' intersection.

Could anyone provide insights into what might be causing this issue or suggest an alternative approach?

enter image description here

1 Answer 1

3

Most likely, your layers are in different CRS.

Consider using the overlay_ group of functions that appear to work even with layers in different CRSes. The functions return an array of matching values, which you can then further transform, filter, concatenate etc. using array functions.

Your expression can be rewritten using overlay_intersects() like so:

array_max(overlay_intersects('Layer1', "WLevelMax"))
1
  • Indeed, the original expression works fine on two layers with the same CRS, or by adding the transform function to one of the geometries inside intersects(). However, this solution is much more elegant, especially as it handles the coordinate transformation internally.
    – Matt
    Feb 6 at 12:52

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.