Skip to main content
- Edited QGis version
Source Link

Qgis version : 2.18.1

I just want to print the ids of the selected features of a certain layer (I should specify that this layer is stored in a sptialitespatialite database), but even if I specified the correct one and manually selected features in it I can't access them via the console.

here is my code:

layer1 = QgsMapLayerRegistry.instance().mapLayersByName("Sites_atelier_vienne")[0]

selfeat = layer1.selectedFeatures()

and the result when I print :

print selfeat
[]

But my layer (and I checked, I have the right one in layer1) have selected features so I'm kind of stuck here.

I just want to print the ids of the selected features of a certain layer (I should specify that this layer is stored in a sptialite database), but even if I specified the correct one and manually selected features in it I can't access them via the console.

here is my code:

layer1 = QgsMapLayerRegistry.instance().mapLayersByName("Sites_atelier_vienne")[0]

selfeat = layer1.selectedFeatures()

and the result when I print :

print selfeat
[]

But my layer (and I checked, I have the right one in layer1) have selected features so I'm kind of stuck here.

Qgis version : 2.18.1

I just want to print the ids of the selected features of a certain layer (I should specify that this layer is stored in a spatialite database), but even if I specified the correct one and manually selected features in it I can't access them via the console.

here is my code:

layer1 = QgsMapLayerRegistry.instance().mapLayersByName("Sites_atelier_vienne")[0]

selfeat = layer1.selectedFeatures()

and the result when I print :

print selfeat
[]

But my layer (and I checked, I have the right one in layer1) have selected features so I'm kind of stuck here.

edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Source Link

Pyqgis - selectedFeatures() doesn't seems to work

I just want to print the ids of the selected features of a certain layer (I should specify that this layer is stored in a sptialite database), but even if I specified the correct one and manually selected features in it I can't access them via the console.

here is my code:

layer1 = QgsMapLayerRegistry.instance().mapLayersByName("Sites_atelier_vienne")[0]

selfeat = layer1.selectedFeatures()

and the result when I print :

print selfeat
[]

But my layer (and I checked, I have the right one in layer1) have selected features so I'm kind of stuck here.