3

I have been using the "Join attributes by location (summary)" tool in QGIS to help create heatmaps. I am wondering if there is a way to only join a feature if it overlaps more than 50% inside the respective area. For example, the picture below:

Orange represents a count of 1 and red a count of 0. I would prefer that only the bottom polygon is orange because it contains the majority of the green feature.

Any ideas?

enter image description here

4
  • An idea for a workaround, at least for regular shaped polygons: create the centroid of the polygon and use this to join: centroid ($geometry). In most cases the centroid will be in the part where the majority of the polygon lies. Just a heuristc approximation, however. There are for sure better solutions.
    – Babel
    Nov 4, 2020 at 20:06
  • Want to make sure I am understanding you correct. Are you saying that my green polygon will most likely lie somewhere on a polygons centroid? If this is true, I don't think it will work because my green features here are pretty small compared to the polygons. I would bank that most would not touch the centroid.
    – Binx
    Nov 4, 2020 at 22:56
  • 1
    No: create the centroid of the green polygon. This centroid normally should lie on the polygon (orange) that should get the attributes, right?
    – Babel
    Nov 5, 2020 at 7:25
  • @babel yes that is correct.
    – Binx
    Nov 5, 2020 at 21:33

1 Answer 1

3

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

Let's assume we have two polygon layers "LayerA" (red dashed with black outline) and "LayerB" (light blue) respectively with its' corresponding attribute tables, see image below.

input

With the following query, it is possible to achieve the result, i.e. to only join a feature if it overlaps more than 30% inside the respective area.

SELECT a.*, GROUP_CONCAT(b.id) AS info
FROM "LayerA" AS a
JOIN "LayerB" AS b ON st_intersects(a.geometry, b.geometry)
WHERE (st_area(st_intersection(a.geometry, b.geometry))/st_area(a.geometry))*100 > 30
GROUP BY a.id

The output Virtual Layer will look like as following

result1

To include a count for that polygon, please adjust the query accordingly

SELECT a.*, GROUP_CONCAT(b.id) AS info, COUNT(b.geometry) As num_feat
FROM "LayerA" AS a
JOIN "LayerB" AS b ON st_intersects(a.geometry, b.geometry)
WHERE (st_area(st_intersection(a.geometry, b.geometry))/st_area(a.geometry))*100 > 30
GROUP BY a.id

The output Virtual Layer will be the following

result2


References:

2
  • I understand your logic here, but how do I include a count for that polygon? Such as lets say you had four LayerA's where all were >50% within group 7. Then output 4 (as the count).
    – Binx
    Nov 5, 2020 at 21:42
  • I'll give that look today!
    – Binx
    Nov 10, 2020 at 18:16

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.