I am working on a project where I have one shapefile with regional districts of Germany, and another with many small biotope polygons which are overlapping with those regions. Meaning one region contains many of those biotopes. Added to these biotopes are many columns of data.
What I am trying to do, is to add data of exactly one biotope polygon to each polygon in the regions shape. Basically the data of the biotope polygon with the smallest value in column "x" should be added to the region shape file which contains the biotope.
I did find the join by location summary function, but of course then it only adds the smallest value of column "x" to the polygon, but not all the other values.
Since I am still quite new to QGIS I might be missing an obvious solution.
How do I add the data from one (of many) polygon to a second one containing the first, but only if the first polygon has the lowest value in column "X"?
-
2Please edit your question and try to summarize your issue in one sentence with a question mark at the end. That will improve the clarity of your question.saQuist– saQuist2022年11月17日 12:51:30 +00:00Commented Nov 17, 2022 at 12:51
1 Answer 1
You can use a Field Calculator expression on your regions layer like so:
array_min(
overlay_contains(
'biotope layer', -- the name of the layer containing the biotope polygons
"X" -- the name of the field from which to take the lowest value
)
)
Result:
The large labels in the image below are the calculated values in the regions layer, the small labels represent the "X" values in the biotopes layer.
Note:
I use overlay_contains
rather than overlay_intersects
else the lower left 'region' would be assigned 8 also (its boundary intersects the boundary of the biotope feature in the upper left 'region'). Depending on your data, you may need a more complex predicate. Let me know if you experience problems and I will adjust my answer.