Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/a22e8451885ec5bdb56880e381e90545 to your computer and use it in GitHub Desktop.
Save ThomasG77/a22e8451885ec5bdb56880e381e90545 to your computer and use it in GitHub Desktop.
PyQGIS recipe to learn about selected features and return result as an ordered dict of fields names, values
from collections import OrderedDict
layer = iface.activeLayer()
features = layer.selectedFeatures()
if len(features) > 0:
fields = [field.name() for field in features[0].fields()]
for f in features:
ordered_dict = OrderedDict(zip(fields, f.attributes()))
# Get an ordered dict
print(ordered_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment