I have a mix of KMLs (points/lines/polygons) and I'm trying to merge them into one feature class. I've tried to "Merge Vector Layers", but it says all layers must have the same geometry.
-
2Because "all layers must have the same geomerty" in a layer. This is the nature of the GIS layer. – Kadir Şahbaz Mar 03 '23 at 14:22
-
2Clarification: the same geometry does not mean the same geometry, but the same geometry type. That is, all layers to be merged must be either points, lines, or polygons. – user30184 Mar 03 '23 at 14:27
1 Answers
In most GIS software including QGIS, individual layers can only have one geometry type (point, line, polygon; single vs multi; 2D vs 3D). And they contain geometry fields and attributes for each feature, but no styling information.
In contrast, KML files are a container that has features that can be stored in a folder structure, with styling and other information, and mixing geometry types.
If your individual KMLs happen to have just one geometry type, you can just import them as layers. But you will then have to merge the KML-sourced layers containing different geometry types separately, in particular in your case into separate "merged points", "merged lines", and "merged polygon" layers.
Once you have done this, you could put those 3 separate merged layers into a group in the QGIS layer tree to handle them jointly in the user interface.
If your individual KMLs have multiple geometry types and/or multiple folders, the native QGIS Add layer... import mechanism will be awkward to use, forcing you to pick from menus and/or pulling only the first geometry type x folder that it encounters (I think this depends on version, not sure). You may find the KML Tools plugin (https://plugins.qgis.org/plugins/kmltools/) helpful to get around this. This also solves problems if any source KML file explicitly contains MultiGeometry entries (as opposed to merely a mix of geometries). See Open a KML with MultiGeometry's in QGIS 3.12 for this specific wrinkle if applicable.
Thinking ahead, after you succeed, you may with to change the display of features in the combined layers based on their attributes or source file. There are breadcrumbs for this starting at QGIS/QDAL: Accessing OGR_STYLE across all layers in a KML file
Finally, if you have many KML files to process, you may find using OGR via the command line (or via Python) preferable to using the QGIS UI (QGIS uses OGR under the hood). See Automatically split KML into point, line and polygon SHPs? as a starting point for that in the KML mixed-geometry context.
- 7,976
- 19
- 48