6

I have nearly a thousand layers of geospatial data consisting only of Point layers and Line Layers and I just want to make it so that I only have one layer for each type.

Is there a way to filter to only run the Data Management Tools > Merge Vector Layers on just one type of layer at a time (e.g. Points only first and then Layer)?

Or at least on how to load only one of them at a time into QGIS? The data is from a (single) KMZ file.

enter image description here

4
  • Only load the line layers and merge them, then do the same for the points. tada.
    – Erik
    Commented Sep 8, 2021 at 7:50
  • 2
    @Erik, I can't. those layers are already stored as one KMZ/KML file. I have updated my question to be more clear Commented Sep 8, 2021 at 7:52
  • You simply could remove the layers of the type you don't need, then.
    – Erik
    Commented Sep 8, 2021 at 8:12
  • 1
    @Erik with hundreds of layers it's going to be very cumbersome. So better reload to file and select there the geometry type.
    – Babel
    Commented Sep 8, 2021 at 8:15

2 Answers 2

4

You can use PyQGIS:

layerlist = []
for lyr in QgsProject().instance().mapLayers().values(): #For every layer added to the map
    if lyr.geometryType()==1: #1 is line, 2 polygon, 0 point
        layerlist.append(lyr) #If the geometrytype is 1, then append the layer to layerlist

processing.runAndLoadResults("native:mergevectorlayers", {'LAYERS':layerlist,'CRS':None,'OUTPUT':'TEMPORARY_OUTPUT'})

enter image description here

And if you want to you can automate the merging by grouping the geometry types using collections.defaultdict(list):

from collections import defaultdict as dd

list_them = dd(list)

numtoname = {0:'points', 1:'lines', 2:'polygons'}
for lyr in QgsProject().instance().mapLayers().values():
    list_them[numtoname[lyr.geometryType()]].append(lyr)
    
for geomtype, layerlist in list_them.items():
    print(geomtype)
    print(layerlist)
    processing.runAndLoadResults("native:mergevectorlayers", {'LAYERS':layerlist,'CRS':None,'OUTPUT':'TEMPORARY_OUTPUT'})

enter image description here

0
4

When you create a new, empty project and you load the kmz file, you can choose to load only point- or only line layers. Select one of them and do processing separately.

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.