I have two polygon layers - call them Layer 1 and Layer 2. Conceptually speaking, they represent two different versions of the same dataset.

I want to perform pairwise Boolean operations on corresponding polygons in each layer. That is, I want a single layer which contains the union/intersection/difference/... of every pair of polygons with the same value of an attribute.

In the following example, I have Layer 1 and Layer 2 and I want to generate the two features in the pairwise intersection layer:

Example of what I am looking for

Conceptually, the pairwise intersection shows me the areas of land that have remained in polygons A and B between the two versions of the dataset. (In reality my layers have many more than 3 polygons.)

I have written an R script to solve this problem, but I am wondering if there is a way to do it entirely using the QGIS user interface.

In recent versions, QGIS has a feature that allows you to iterate over every feature of a layer, but I can't see how this can be applied in this situation. What's more, the QGIS Graphical Modeler doesn't seem to support loops.


1 Answer 1


You can use DB Manager standard plug-in and SQL query on your project layers (even if these are not stored in an RDBMS). I suppose your layers have an id column which is a unique identifier for the features.

  1. Open the two layers (I draw something similar to your layers) using new and old for layer names enter image description here

  2. Enable DB Manager plug-in Plugins/Manage and Install Plugins... from the menu

  3. Open DB Manager using Database/DB Manager... from the menu

  4. Open the Virtual Layers and Project layers (if your data is in Geopackage or PostGIS or SpatiaLite open the other group)

  5. Select the second icon from the toolbar of DB Manager (spanner icon)

  6. Input the following SQL command:

    select new.id, st_intersection(new.geometry, old.geometry) as geometry from new inner join old on (new.id = old.id) enter image description here

  7. Click on Execute and check Load as new layer

  8. Check Column with unique values and select id column and check Geometry column and select geometry

  9. Finally click on Load button

You should get a Query_layer in your project with the result: enter image description here

  • There is still coding involved here, but of course the problem becomes so simple when you break it down using spatial SQL, so it's well worth it! Great answer. Commented Dec 27, 2020 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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