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.
Polygon self-intersection tool and select layer name and its identifier (
id field). Just click on
- 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 like
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.