# get the fields and features:
fields = indiv.fields()
features = indiv.getFeatures()
# initialise an empty dict with each field name:
attdict = {}
for field in fields:
attdict[field.name()] = []
# for each field in each feature, append the relevant field data to the dict item:
for feature in features:
for field in fields:
v = feature[field.name()]
attdict[field.name()].append(v)
print(attdict)
That gives a dict
that looks like this for some Ghana regions:
{'shapeName': ['Greater Accra', 'Central', 'Western', 'Eastern', 'Ashanti', 'Volta', 'Brong Ahafo', 'Northern', 'Upper West', 'Upper East'],
'shapeISO': ['GH-AA', 'GH-CP', 'GH-WP', 'GH-EP', 'GH-AH', 'GH-TV', 'GH-BA', 'GH-NP', 'GH-UW', 'GH-UE'],
'shapeID': ['GHA-ADM1-1590546715-B1', 'GHA-ADM1-1590546715-B2', 'GHA-ADM1-1590546715-B3', 'GHA-ADM1-1590546715-B4', 'GHA-ADM1-1590546715-B5', 'GHA-ADM1-1590546715-B6', 'GHA-ADM1-1590546715-B7', 'GHA-ADM1-1590546715-B8', 'GHA-ADM1-1590546715-B9', 'GHA-ADM1-1590546715-B10'],
'shapeGroup': ['GHA', 'GHA', 'GHA', 'GHA', 'GHA', 'GHA', 'GHA', 'GHA', 'GHA', 'GHA'], 'shapeType': ['ADM1', 'ADM1', 'ADM1', 'ADM1', 'ADM1', 'ADM1', 'ADM1', 'ADM1', 'ADM1', 'ADM1']}
Which I think is what you are after.
indiv=
andfor feature in features:
that you've not shown. One line to getfeatures
from the layer and another to getfield
, or better still all the field names.