2

I have two layers: district (with lots of districts) and an object layer. I want to add the information where the object lies in the most to the object.

For example: this object lies the most in district B, so it should add 'B' to a column in the objects attribute table.

enter image description here

I tried spatial joins but i am not getting what i am searching for.

Does anyone know how to get there?

1
  • Thanks worked great!
    – soeren
    Commented May 5, 2022 at 14:27

2 Answers 2

4

Use QGIS expressions with this expression:

array_first (
    overlay_intersects( 
        'Districts',  -- Replace with the name of the layer
        $id,
        sort_by_intersection_size:='des'
    )
)

The parameter sort_by_intersection_size works since QGIS 3.24, see visual changelog.

enter image description here

1
  • Thanks, worked also great!
    – soeren
    Commented May 5, 2022 at 14:26
3

Let's assume there are two polygon layers one called 'grid_test' (green) and the second called 'grid_test2' (orange), see image below.

input

Apply the "Join attributes by location" tool with the 2 — Take attributes of the feature with largest overlap only (one-to-one) for the 'Join type':

settings

and get the output like this:

result

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.