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)

enter image description here

I know there is a tool that does the trick in ArcGIS, but is there a QGIS solution?

  • This sounds a lot like a job for the OGR Virtual Format combined with a SQLite statement. – Kersten Jul 23 '15 at 8:40
  • Indeed i would prefer not to go through SQL. But it look like i will have too, But In that case I will go with Postgis. cheers – julsbreakdown Jul 23 '15 at 8:59
  • 1
    For information, since qgis 2.14.3 the processing algorithm now take a list of layers instead of two layers – julsbreakdown Mar 14 '17 at 18:53
  • Try merging the 3 layers (not the one with the black area) and then run the Singleparts to multiparts tool on the merged layer. Then use SAGA's Intersect tool and check the Split parts option. Hopefully, the black area should be a separate feature in the output layer. You can then save the black area feature in a new layer then run the Join attributes by location tool using the new black area layer and the merged layer as inputs to get the count field. – Joseph Jun 16 '17 at 11:37
  • I don't have time to try it out but there is in the QGIS algorithms dialog boxes a green curved arrow for iteration of the inputs. You might fiddle around with that; the nice thing is you can use temporary layers. docs.qgis.org/2.2/en/docs/training_manual/processing/… – johns Jun 16 '17 at 12:42

For a layer's feature to be represented in all layers it must be represented in any selection of two layers a well. Using this theory you can simply run multiple intersection functions according to the order below. The example assumes 4 total layers named Layer1, Layer2, Layer3, and Layer4.

  1. Run an intersection between Layer1 and Layer2 to get Output1.
  2. Run an intersection between Output1 and Layer3 to get Output2.
  3. Run an intersection between Output2 and Layer4 to get Output3.

Output 3 should contain all features that appear in all 4 layers. For the 'Count' field, I think you can just file it with the number of layers involved in the intersect, unless I am mistaking what data you want that field to hold.

This method isn't eloquent and if you have many layers or layers with many features it could prove time consuming but it should work and is a simple process to put together.

| improve this 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 :

ALGORITHM: Merge vector layers
    LAYERS <ParameterMultipleInput>
    OUTPUT <OutputVector>

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:
                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


ALGORITHM: v.overlay - Overlays two vector maps.
    ainput <ParameterVector>
    atype <ParameterSelection>
    binput <ParameterVector>
    operator <ParameterSelection>
    -t <ParameterBoolean>
    GRASS_REGION_PARAMETER <ParameterExtent>
    GRASS_MIN_AREA_PARAMETER <ParameterNumber>
    GRASS_OUTPUT_TYPE_PARAMETER <ParameterSelection>
    output <OutputVector>

STEP 3 Joseph answer seems decent

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.