1

To formulate my question with a concrete example: I have two multi-polygon layers of the same city.

  • Layer A has polygons of the city divided in parts e.g. north, south, west, east.
  • Layer B has smaller polygons that represent green e.g. trees, forests, parks and such.

Now I want to add a new column "city_part" in the attribute table of layer B. And likewise I'd want an either QGIS-expression- or Python-coded script, that can figure out in which polygon of layer A every single polygon of layer B lies. So the concrete result would be a layer B in which every polygon's got a new attribute, telling whether it resides inside north, south, west or east. How can this be done?

1
  • 1
    a spatial join would also work. use the tool join attributes by location.
    – csk
    Dec 20, 2019 at 21:19

1 Answer 1

2

One way of many:

  • install refFunctions plugin
  • with your greens layer active

    • open Field Calculator
    • Create a new field

      • choose Output field name (e.g. 'city_part')

      • choose Output field type to match that of the city parts layers id column (ì.e. Text)

    • use expression:

      geomintersects( '<city_parts_layer_name>', '<city_parts_id_column_name>')
      

      and hit Ok

This assumes the city parts polygon id has the values north, south, east, west. It also assumes uniqueness of the intersections; if one of the smaller polygons intersects multiple city parts, it is internal order based which one will get assigned.

2
  • geomintersects() wasn't recognized, which plugin do I have to install to have this function? Dec 20, 2019 at 11:44
  • Ops, forgot: those functions are part of the refFunctions plugin; see update for link
    – geozelot
    Dec 20, 2019 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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