QGIS – Concatenate Attribute Data from Point, Line, and Polygon Layers

concatenationqgis

I have data from map interviews consisting of three layers (one point layer, one line layer and one polygon layer) within a geopackage. Each layer has the same field structure (as shown below).

enter image description here

The data from the interview map, are numbered consecutively in the field 'map_no' regardless of whether they are points, lines or polygons. I would like to concatenate the data from the three layers into a single attribute table, sorted on 'map_no'. Ideally, this table would be automatically updated when items are added into any of the separate point, line or polygon layers. This would allow me to see all of the data with the records in the correct order. Also (ideally) the geometry for each layer would be included, but I recognize that this may be impossible. At the very least, I would like to be able to view the attribute data together and to export it.

I am guessing that this could be done with a virtual layer, but I have no idea how and have not yet found any hints online.

Best Answer

You can use a virtual layer to aggregate the attributes.

For the geometry it, kind of work a bit, as you can pan/zoom to the geometry but it won't be shown on the map, i.e. you would still have to display the initial layers.

Go to the menu Layer > Add Layer > Add/Edit Virtual Layer... and enter the query

select * from (
    select * from myPointLayer
    union all
    select * from myLineLayer
    union all
    select * from myPolygonLayer)
order by map_no;

If the fields are not the same, or not in the same order, you would have to replace each * by the field name list.

Related Question