Bug report #7887

Python AttributeError: 'QgsVectorLayer' object has no attribute 'getFeatures'

Added by Dan Jones almost 11 years ago. Updated almost 11 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:-
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:16760

Description

I've checked the API docs and the API change log and QgsVectorLayer has a getFeatures() method but when I try to call this from my script (excerpt below) I get an attribute error.

rect = QgsRectangle(x-rad,y-rad,x+rad,y+rad)
layer = iface.activeLayer()
wind = layer.getFeatures(QgsFeatureRequest().setFilterRect(rect))

.. results in traceback ..

Traceback (most recent call last):
File "C:/.. ../python/plugins\\scriptrunner\\scriptrunner.py", line 481, in run_script
user_script.run_script(self.iface)
File "C:/.. ..\\LayerIteratorTest.py", line 44, in run_script
wind = iface.activeLayer().getFeatures(QgsFeatureRequest().setFilterRect(rect))
AttributeError: 'QgsVectorLayer' object has no attribute 'getFeatures'

I'm using QGIS 1.8.0 Lisboa and Python 2.7 and Script Runner plugin 0.71 on Windows 7 Professional querying data from a shapefile layer. Information about version and build below:

QGIS version
1.8.0-Lisboa
QGIS code revision
f440b60
Compiled against Qt
4.7.1
Running against Qt
4.7.1
Compiled against GDAL/OGR
1.9.2
Running against GDAL/OGR
1.9.2
GEOS Version
3.3.6
PostgreSQL Client Version
8.3.10
SpatiaLite Version
3.0.1
QWT Version
5.2.1
This copy of QGIS writes debugging output.

LayerIteratorTest.py Magnifier - Full python script code (2.02 KB) Dan Jones, 2013-05-23 03:07 AM

History

#1 Updated by Jürgen Fischer almost 11 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

QgsVectorLayer.getFeatures() is new in master and doesn't work on 1.8.

Also available in: Atom PDF