QGIS – Merge Shapefiles with Equal Geometries but Different Attributes

featuresgeometrymergeqgisshapefile

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.

input

Step 1. Create a unique "id" in one layer, using for instance $id+ 1 or @row_number.

step_1

Step 2. Get that unique "id" by comparing geometries using the overlay_equals() function in the Field Calculator.

I used this expression:

overlay_equals('dresden_buildings_test', "id")[0]

and got this output:

result

Hereafter I check if they are the same

check

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.

Related Question