I have a QGIS project with several shapefiles like the one in following image. I want to know how many times the shapefiles overlap and where is produced a gradient.
I think the best option is to transform the polygons in a grid line 1km*1km with data presence/absence to produce the gradient. But I am not pretty sure if this is possible and how to do it.
Answer
This is another approach using SAGA Polygon self-intersection tool, which can be accessed through QGIS Processing Tools | SAGA | Vector polygon tools | Polygn self-intersection
. (I am not sure but this tool probably became available from QGIS 2.18.13).
The above image shows a sample polygon layer, in which nine polygons are partially overlapping each other. Currently I have one id
field only.
Then:
- Activate
Polygon self-intersection
tool and select layer name and its identifier (id
field). Just click on[Run]
button. - It will generate a new polygon layer named
Intersection
, which overlapping parts of polygons are divided into individual pieces. Open its attribute table. - The attribute table will show a new field
ID
which is something like2|1
,3|2
, ... indicates overlapped ids. (Please also see the image below). - Create new field with an expression
length("ID") - length(replace("ID", '|', '')) + 1
. This (my_counts
in my test case) is the count how many polygons were overlapping at each location.
Above image is labeled by the overlapping counts. (Please note the polygons were separately colored by another field ($rownum
), which I added afterwards).
Finally, please use this counts field to set your gradient color.
No comments:
Post a Comment