Last active
January 19, 2016 10:44
-
-
Save SzieberthAdam/c85ee367a17b307eea27 to your computer and use it in GitHub Desktop.
PyQGIS: Get fields of layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# QgsFields() of QgsVectorLayer() | |
# fields = layer.fields() # from QGIS 1.12+ | |
fields = layer.pendingFields() # and below... | |
# list QgsField() from QgsFields() | |
fieldlist = fields.toList() | |
# list of layer fieldnames | |
[f.name() for f in fieldlist] | |
# field attributes | |
fattr = ('name', 'type', 'typeName', 'length', 'precision', 'comment') | |
# print the field table of a layer | |
for f in fieldlist: | |
print '; '.join(['{!r}'.format(getattr(f, a)()) for a in fattr]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment