[GIS] Merging multiple vector layers to one layer with multiple geom types with QGIS

qgisqgis-pluginsqgis-processing

I have a situation where I need to merge a large number of spatial files into a single output with a free tool like QGIS, rather than FME or Alteryx.

Along the lines of this post:
Merging multiple vector layers to one layer using QGIS?

However, I have some point features, some line features, and some polygon features. This rules out outputs like shapefiles, but anything else is fine like GML, TAB, or a database.

Is there anyway to do this in QGIS?

Every process or model I try makes a shapefile at some point which means this can't work.

Best Answer

You can merge layers with different geometry types together with ogr2ogr.

Here is an example about merging an point shapefile and polygon shapefile into GeoPackage as a new layer "merged" that has a generic geometry type.

ogr2ogr -f gpkg merged.gpkg point.shp -nln merged -nlt geometry
ogr2ogr -f gpkg -update -append merged.gpkg polygon.shp -nln merged -nlt geometry

ogrinfo merged.gpkg merged
INFO: Open of `merged.gpkg'
      using driver `GPKG' successful.

Layer name: merged
Metadata:
  DBF_DATE_LAST_UPDATE=2017-03-31
Geometry: Unknown (any)
Feature Count: 2
Extent: (309.000000, 478.000000) - (599.000000, 604.000000)
Layer SRS WKT:
(unknown)
FID Column = fid
Geometry Column = geom
attr: String (1.0)
OGRFeature(merged):1
  attr (String) = B
  POINT (382 478)

OGRFeature(merged):2
  attr (String) = A
  POLYGON ((309 584,599 604,466 493,309 584))

However, you will have some problems with QGIS with using that layer because QGIS can't handle points, lines, and polygons on a same layer. QGIS requires that layer is split by the geometry type

enter image description here

You can open the merged layer as a single layer with OpenJUMP.

Related Question