[Qgis-developer] Getting and setting attribute field names and
values for vector layers
Alexander Bruy
alexander.bruy at gmail.com
Wed Dec 7 08:06:08 EST 2011
Hi Ole,
2011/12/7 Ole Nielsen <ole.moller.nielsen at gmail.com>:
> Thanks for that - I wouldn't have known where to look. But this does the
> trick - although for my application I did have a need to explicitly convert
> the QString types to unicode.
> I looked at methods toAscii() and toLatin1() but neither produced the python
> string types I was expecting. Can you comment on that?
To convert QString into Python string use str() or unicode() functions.
For example, in code
attrs = feat.attributeMap()
for (k,attr) in attrs.iteritems():
name = fields[ k ].name()
print "%s: %s" % (name, unicode(attr.toString()))
# print "%s: %s" % (name, str(attr.toString()))
--
Alexander Bruy
NextGIS
More information about the Qgis-developer
mailing list