I am trying to create new instance attributes (NOT feature attributes) for a collection of features in a vector layer in PyQGIS. I'm getting some weird results and am wondering if this is even possible. For instance, I can change the instance attributes of a single feature:
أكثر...
feat = iface.activeLayers().getFeatures().next()
feat.NEW = 'attribute'
And it seems to commit to that feature:feat.NEW = 'attribute'
dir(feat)
However, when I try to iterate through the features using a feature iterator, I get no such luck!['NEW', 'class', 'delattr', 'delitem', 'dict', 'doc', 'format', 'geo_interface', 'getattribute', 'getitem', 'hash', 'init', 'iter', 'module', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'setitem', 'sizeof', 'str', 'subclasshook', 'weakref', 'attribute', 'attributes', 'deleteAttribute', 'fieldNameIndex', 'fields', 'geometry', 'geometryAndOwnership', 'id', 'initAttributes', 'isValid', 'setAttribute', 'setAttributes', 'setFeatureId', 'setFields', 'setGeometry', 'setGeometryAndOwnership', 'setValid']
feat.NEW
'attribute'
for feat in iface.activeLayer().getFeatures():
Then check:feat.NEW = 'attribute'
feat = iface.activeLayer().getFeatures().next()
feat.NEW
Traceback (most recent call last): File "", line 1, in AttributeError: 'QgsFeature' object has no attribute 'NEW'
I'm assuming that the feature iterator creates some objects that have access to the features within the layer but does not actually point to the feature objects themselves... does anyone know of a way to iteratively change the instance attributes of PyQGIS objects? Is this even possible?feat.NEW
Traceback (most recent call last): File "", line 1, in AttributeError: 'QgsFeature' object has no attribute 'NEW'
أكثر...