I have two shapefiles, one of which contains building polygons and attributes such as building age and building usage, and the other file contains the same building polygons and attributes such as the building height.
There is no attribute, on which I could merge both datasets, such as an unique "ID"
of a building polygon. The only thing that matches perfectly, are the shapes of the polygons. I want to get to a point to have one file with the building polygons and have all three attributes in there.
Is there an easy way to do this in QGIS? I thought about comparing polygon centroids and go on from there, but maybe there exists a cleaner way.
Best Answer
I would suggest to create that unique
"id"
. The following workflow can be applied.Let's assume there there area two polygon layers 'dresden_buildings_test' and 'dresden_buildings_test2' with features that possess equal geometries but have different attributes (data was taken from https://www.geofabrik.de/de/data/shapefiles.html), see image below.
Step 1. Create a unique
"id"
in one layer, using for instance$id
+ 1
or@row_number
.Step 2. Get that unique
"id"
by comparing geometries using theoverlay_equals()
function in the Field Calculator.I used this expression:
and got this output:
Hereafter I check if they are the same
Alternative to approch in the Step 2. try the "Join attributes by location" with
equals
as 'Geometric predicate'.As @Erik wrote about "centroid" and you said "comparing polygon centroids", however I will probably use the "Point on surface", because building can have holes and strange shapes.