2

I am trying to populate a point layer's field attribute with values from polygon features' attributes that contain point features.

The inverse is very simple:

aggregate(
    layer:='point layer's name',
    aggregate:='max',
    expression:="point layer's field name",
    filter:=intersects($geometry, geometry(@parent))
    )

I need to do the exact opposite, get the attribute from the polygon feature and populate the points contained in said polygon.

I have tried contains/intersects/overlaps/crosses/touches/within to no avail.

I'm limited to doing this with the Field calculator expression or potentially PyQGIS, no SQL or DB Manager.

3
  • I edited my title Nov 24 at 14:32
  • Okay, but now you have two topics in your title. In the Focused question/Best answer model, an "and" in the title is a flag for an unfocused Question.
    – Vince
    Nov 24 at 14:48
  • Retrieving the attribute in and of itself is all I need to actually populate my field, it really is only one question but I will edit my title once more. edit: I edited it once more Nov 24 at 14:50
4

Firstly make sure that your layers spatially overlap i.e. the same location and the same CRS.

Secondly as it says in the documentation for aggregate() function:

The source feature can be accessed with the variable @parent.

So, you can try either this:

aggregate(
    layer:='polygon layer's name',
    aggregate:='max',
    expression:="polygon layer's field name", 
    filter:=contains($geometry, geometry(@parent))
    )

or this:

aggregate(
    layer:='polygon layer's name',
    aggregate:='max',
    expression:="polygon layer's field name", 
    filter:=within(geometry(@parent), $geometry)
    )

Alternatively you can achieve the desired output with the overlay_within() and array_max()functions:

array_max(
    overlay_within(
        layer:='polygon layer's name',
        expression:="polygon layer's field name"
        )
    )
4
  • Hi, as I said in my initial post, I have tried already with within/contains/overlaps/crosses/touches and neither worked unfortunately. I'm also not sure how to use array_max() within an aggregate expression Nov 24 at 16:38
  • Sir, They do overlap and have the same CRS, I use that exact same expression to sum attributes for the points contained inside my polygon. Nov 25 at 6:14
  • Can you please extend your question with more details, e.g if you get an error etc.
    – Taras
    Nov 25 at 6:18
  • I get no error, values returned are simply NULL as if no geometry fitting the filter condition is found. I will shortly edit my post with screenshots explaining my situation a tad better Nov 25 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.