1

I have a vector layer with polygons A, and the second with polygons B. Polygons A includes/are intersected by several polygons B.

I want to join the data (just names of polygons) from polygons B to polygons A (in result polygon A get a field with all names of polygons B witch are intersected by them).

Polygons B are not a 100%-correct. Actually borders of B should be drawn in the same line of A border, but they are not in many of cases.

Is there any way to tell QGIS to join all of intersected B to one A but only if specified minimum %area of B is in A?

The last (I hope) question - output data A includes repeated data (ex. screen).

How could I get rid of duplicates?

enter image description here

2
  • 2
    You must have a unique ID (it's more easier) for your layers and go to the menu Vector > Geoprocessing > Intersects. So you'll have your polygon A layer with B attributes. You can after update your polygon A layer with a join on unique ID. Commented Aug 5, 2021 at 14:10
  • 1
    Does this answer your question? One-to-many spatial join with results in one row Commented Aug 6, 2021 at 5:17

1 Answer 1

3

This is an extension to this answer.

In QGIS I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume there are two polygon layers 'grid_test2' (green) and 'grid_test' (red) respectively, see image below.

input

With the following query, it is possible to achieve the result, i.e. to join all unique "ID"s of intersected 'grid_test' to one 'grid_test2' but only if specified minimum of 'grid_test' is in 'grid_test2'.

SELECT a.*, GROUP_CONCAT(DISTINCT b.id) AS b_ids FROM "grid_test2" AS a LEFT JOIN "grid_test" AS b ON st_area(st_intersection(a.geometry, b.geometry)) > 0.1 GROUP BY a.id 

In the example above I eluded the cell with "ID" = 3 from the 'grid_test' layer, where the intersection area is not large enough (this condition does it st_area(st_intersection(a.geometry, b.geometry)) > 0.1), see image below.

area

The output Virtual Layer will look like as following

result


As an alternative you may try the solution offered in this article "Summary Aggregate and Spatial Filters in QGIS". So, the expression in the Field Calculator for above example will look like:

aggregate(layer:='grid_test', aggregate:='concatenate_unique', expression:=to_string("id"), concatenator:=',', filter:=area(intersection($geometry,geometry(@parent)))>0.1 ) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.