Spatial join based on polygon centroid in QGIS
You can create a virtual layer with the desired join condition
go to the menu Layer > Add Layer > Add/Edit Virtual Layer...
and enter the query
SELECT b.*, p.field1, p.field2
FROM buildings b
JOIN parcels p ON ST_CONTAINS(p.geometry, ST_CENTROID(b.geometry))
Note that it is safer to list the fields of interest from the 2nd layer (parcels) instead of using p.*
, as it ensure that the resulting layer contains a single geometry field - from the 1st layer (building).
Another solution based on existing processing algorithms. You can achieve this by doing 2 spatial joins.
- Extract centeroids via Vector Geometry > Centroids
- Join the centroids layer with parcels layers, call this
centroid_join
- Join the building footprints layer with centroid join.
It is advisable to explicitly specify the fields in each join, so you don't end up with many duplicate fields.