Using: QGIS version 2.12.0-Lyon. No Add-on available.

Problem: I do not know where to start after opening the Python console with regards to writing a script that creates a new layer per value queried from a field within QGIS Desktop. I have experience with arcpy and am trying to start with a basic scripted action to learn Python for QGIS.

At the moment I can list all the attributes found in the "active" layer see below:

    lyr = iface.activeLayer()

    features = lyr.getFeatures()

    for feat in features:
        attrs = feat.attributes()
        print attrs[1]

However, I would like to iterate this and create a new memory layer (i.e. only available whilst the project is open) per feature per attribute creating a new layer where a query is set to equal that attribute (i.e. Name = feat[0])

Can anyone assist in building a template script solution?

This can be partly completed without using Python by using the "Split Vector Layer" tool. However, this tool will create a folder of shapefiles and not "in memory" layers.


I discovered that this question has already been answered find it here:

Duplicate a layer applying a filter in QGIS

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.