Wednesday 25 September 2019

qgis - Convert polygon to grid lines


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.


enter image description here



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).



enter image description here


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:



  1. Activate Polygon self-intersection tool and select layer name and its identifier (id field). Just click on [Run] button.

  2. It will generate a new polygon layer named Intersection, which overlapping parts of polygons are divided into individual pieces. Open its attribute table.

  3. The attribute table will show a new field ID which is something like 2|1, 3|2, ... indicates overlapped ids. (Please also see the image below).

  4. 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.


enter image description here



Above image is labeled by the overlapping counts. (Please note the polygons were separately colored by another field ($rownum), which I added afterwards).


enter image description here


Finally, please use this counts field to set your gradient color.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...