I am trying to find a way with QGIS to get the intersection area of more than 2 layers.
All the tools in QGIS take just the 2 input layers.
For example in the image below, I have 4 layers and I want to retrieve just the black area.
Furthermore, I need to retrieve the count attribute and add it to the intersected area attribute table (in this case 4)
I know there is a tool that does the trick in ArcGIS, but is there a QGIS solution?
Answer
Forgot to post my solution...
STEP 1 : Merge layers
In the end I changed my Qgis Version to 2.14.11, the algorithm takes a single input param (layers) separated by a semicolon :processing.alghelp('qgis:mergevectorlayers
')
ALGORITHM: Merge vector layers
LAYERS
OUTPUT
Prior it was :
processing.runalg('qgis:mergevectorlayers', layer1, layer2, output)
You can also do a loop to use this version of the algorithm
for i, layer in enumerate(layers):
if i == 0:
layer1 = layers[i]
layer2 = slayers[i+1]
processing.runalg('qgis:mergevectorlayers', layer1, layer2, savename)
if i == leng-1:
break
else:
layer1 = QgsVectorLayer(savename, 'temp', 'ogr')
layer2 = sme_layers[i+1]
savename = name
processing.runalg('qgis:mergevectorlayers', layer1, layer2, savename)
STEP2 : overlay the layer with itself
processing.alghelp('grass:v.overlay')
ALGORITHM: v.overlay - Overlays two vector maps.
ainput
atype
binput
operator
-t
GRASS_REGION_PARAMETER
GRASS_SNAP_TOLERANCE_PARAMETER
GRASS_MIN_AREA_PARAMETER
GRASS_OUTPUT_TYPE_PARAMETER
output
STEP 3 Joseph answer seems decent
No comments:
Post a Comment