Geographic Information Systems Asked by Alan Thomas on June 22, 2021
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:
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.
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.
Open the two layers (I draw something similar to your layers) using new
and old
for layer names
Enable DB Manager
plug-in Plugins/Manage and Install Plugins...
from the menu
Open DB Manager
using Database/DB Manager...
from the menu
Open the Virtual Layers
and Project layers
(if your data is in Geopackage or PostGIS or SpatiaLite open the other group)
Select the second icon from the toolbar of DB Manager
(spanner icon)
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)
Click on Execute
and check Load as new layer
Check Column with unique values
and select id
column and check Geometry column
and select geometry
Finally click on Load
button
You should get a Query_layer
in your project with the result:
Correct answer by Zoltan on June 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP