1

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.

menes
  • 1,421
  • 2
  • 7
  • 24
spk578
  • 1,516
  • 1
  • 11
  • 27
  • 2
    See https://gis.stackexchange.com/questions/173936/how-to-create-memory-layer-and-populate-fields for creating a duplicate memory layer. – Germán Carrillo Sep 11 '17 at 04:22

1 Answers1

0

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

Duplicate a layer applying a filter in QGIS

spk578
  • 1,516
  • 1
  • 11
  • 27