Let's say I have the scenario where:

  • Polygons A and B intersect polygon C
  • There are also polygons X,Y and Z which do not intersect C.
  • Polygon C has an attribute value 'Priority' which I need the value propagated onto intersecting polygons (that is, onto Poly A and B).

All the data is in a single layer in a GeoPackage table.

I have no drama's selecting polygons A and B, I'm looking at trying to update them using the Field Calculator and an expression. But I'm having an absolute brain fade as to how to refer to self.

That is - how do I find intersecting polygons on the layer that I'm already using and get their attribute values?

My logic is to write a function and apply it to a selection set (which I would select outside of the function). So far I have the following:

def get_value_func():
    # Firstly, get the set of polys I want to grab values for. Lets just use the 'c' poly for now
    geometry_col = collect($geometry, , filter:="layer_name" = 'c')

    #then lets test if the current geometry intersects anything within the geometry collection
    if(intersect($geometry, geometry_col), update_val = <THIS IS THE BIT IM NOT SURE ABOUT>))

    return update_val

Its possible I'm overcomplicating things and am happy to hear other ideas about how to achieve this. Maybe collection isn't the right data structure to be using.


2 Answers 2


You can use the aggregate() function for this task. see the following situation - hope that describes what your are trying to do:

enter image description here

with the following expression you will aggregate values from the field myfield into a new field intersects for the polygons which intersects other polygons in the same layer:

          filter:=intersects($geometry, geometry(@parent))
                  and "myfield" <> attribute(@parent, 'myfield'),

in the filter you will need 2 conditions to avoid the self intersection of each polygon within the result.

  • @parent looks like the missing piece to my puzzle..... im so used to object orientated languages and using '_self'. ....ill give this a try, thanks for that.
    – nr_aus
    Commented May 14, 2021 at 7:17
  • 1
    @parent works only in context of the attribute() function an is the calling/parent feature...
    – eurojam
    Commented May 14, 2021 at 7:26
  • ok cheers for that extra bit of info.
    – nr_aus
    Commented May 17, 2021 at 2:11

If you use QGIS 3.16 or later, you can use overlay_intersects() together with @layer variable that refers to the current layer. Use this expression in the Field Calculator:

        array_first (

enter image description here

  • Thanks for that, looks good.
    – nr_aus
    Commented May 17, 2021 at 2:14

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.