4

In QGIS Python, how to get alias of field. In class QgsField, i can not find method to do this.

lay = iface.activeLayer()
provider = lay.dataProvider()
fields = provider.getFields()

for field in fields:
    print field.[SOMETHING]
3

If your attributes have aliases, you can get a Python dictionary of aliases calling:

lay = iface.activeLayer()
lay.attributeAliases()

This gives you something like:

{u'type': u'Municipality Type', u'name': u'Municipality Name'}

If you have a specific field index and you want to get its alias, you can use:

lay.attributeAlias( fieldIndex )

Which gives you something like:

u'Municipality Name'
  • 1
    thank you. It is interested, that QgsField does not handle own alias. – Marcel GJS May 15 '16 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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