2

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.

2
  • 1
    1. A feature is a geometry. What you want to join are attributes. 2. join attributes by location does what you want. If you get too many duplicate geometries, try a different join type, or create centroids for one of your layers and then join the centroids to the other polygon layer.
    – Erik
    Commented Nov 19, 2021 at 9:21
  • I deleted the geopandas tag because no code was provided.
    – Taras
    Commented Nov 19, 2021 at 10:11

2 Answers 2

3

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.

2

Try "Join attributes by location" with geometric predicate setting as equal.

enter image description here

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.