Created
June 6, 2020 13:02
-
-
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
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
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