Skip to main content
added 72 characters in body
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

The QgsJsonUtils class has exportAttributes method for getting attributes as a dict.

Solution 1:

Making a dictionary including feature "id" as key, attributes map as value:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
from qgis.core import QgsProject

layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
from qgis.core import QgsProject

layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]

The QgsJsonUtils class has exportAttributes method for getting attributes as a dict.

Solution 1:

Making a dictionary including feature "id" as key, attributes map as value:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]

The QgsJsonUtils class has exportAttributes method for getting attributes as a dict.

Solution 1:

Making a dictionary including feature "id" as key, attributes map as value:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
from qgis.core import QgsProject

layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
from qgis.core import QgsProject

layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]
added 160 characters in body
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

QgsJsonUtils The QgsJsonUtils class has exportAttributesexportAttributes method for getting attributes as a dict.

Solution 1:

Making a dictionary including feature id"id" as key, attributes map as value:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]

QgsJsonUtils class has exportAttributes method for getting attributes as dict.

Solution 1:

Making a dictionary including feature id as key, attributes map as value:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]

The QgsJsonUtils class has exportAttributes method for getting attributes as a dict.

Solution 1:

Making a dictionary including feature "id" as key, attributes map as value:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]

features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]
deleted 24 characters in body
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

QgsJsonUtils class has exportAttributes method for getting attributes as dict.

Solution 1:

Making a dictionary including feature id as key, attributes map as value like:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features without ids like:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]

QgsJsonUtils class has exportAttributes method for getting attributes as dict.

Solution 1:

Making a dictionary including feature id as key, attributes map as value like:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features without ids like:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]

QgsJsonUtils class has exportAttributes method for getting attributes as dict.

Solution 1:

Making a dictionary including feature id as key, attributes map as value:

{feature1.id: {attr1: value, attr2: value, ...},
 feature2.id: {attr1: value, attr2: value, ...},
 ...}
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_dict = {f.id(): QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()}

Solution 2:

Making a list including attributes map (dict) of features:

[{attr1: value, attr2: value, ...}, # feature 1
 {attr1: value, attr2: value, ...}, # feature 2
 ...]
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')[0]
features_list = [QgsJsonUtils.exportAttributes(f) for f in layer.getFeatures()]
added 12 characters in body
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404
Loading
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404
Loading