Skip to main content
deleted 9 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to get Getting features by attribute using PyQgis?

How can I get a feature's geometry from selection by attribute.?

For instance from a point layer I want to get the geometry by the field CODICE filter (CODICE = A001).

I tried with:

layer = QgsMapLayerRegistry.instance().mapLayersByName("My_layer")[0]
selection = layer.getFeatures(QgsFeatureRequest(QgsExpression("\"CODICE\" = 'A001'")))
geom = selection.geometry()

It doesn't work, and the python console error is:

AttributeError: 'QgsFeatureIterator' object has no attribute 'geometry'

Thanks

AttributeError: 'QgsFeatureIterator' object has no attribute 'geometry'

How to get features by attribute using PyQgis?

How can I get a feature's geometry from selection by attribute.

For instance from a point layer I want to get the geometry by the field CODICE filter (CODICE = A001).

I tried with:

layer = QgsMapLayerRegistry.instance().mapLayersByName("My_layer")[0]
selection = layer.getFeatures(QgsFeatureRequest(QgsExpression("\"CODICE\" = 'A001'")))
geom = selection.geometry()

It doesn't work, and the python console error is:

AttributeError: 'QgsFeatureIterator' object has no attribute 'geometry'

Thanks

Getting features by attribute using PyQgis?

How can I get a feature's geometry from selection by attribute?

For instance from a point layer I want to get the geometry by the field CODICE filter (CODICE = A001).

I tried with:

layer = QgsMapLayerRegistry.instance().mapLayersByName("My_layer")[0]
selection = layer.getFeatures(QgsFeatureRequest(QgsExpression("\"CODICE\" = 'A001'")))
geom = selection.geometry()

It doesn't work, and the python console error is:

AttributeError: 'QgsFeatureIterator' object has no attribute 'geometry'

Source Link
Chlorine
  • 63
  • 1
  • 3

How to get features by attribute using PyQgis?

How can I get a feature's geometry from selection by attribute.

For instance from a point layer I want to get the geometry by the field CODICE filter (CODICE = A001).

I tried with:

layer = QgsMapLayerRegistry.instance().mapLayersByName("My_layer")[0]
selection = layer.getFeatures(QgsFeatureRequest(QgsExpression("\"CODICE\" = 'A001'")))
geom = selection.geometry()

It doesn't work, and the python console error is:

AttributeError: 'QgsFeatureIterator' object has no attribute 'geometry'

Thanks