[Qgis-developer] Python and strange results using layer(.dataProvider()).getFeatures(...)

Casper Børgesen (CABO) CABO at NIRAS.DK
Tue Aug 30 05:32:41 PDT 2016


Hi,

I have a point SHAPE layer with 4 points on a line (just to make them easy to number in this example, and the layer is created in QGIS).


1.       Start editing.

2.       Delete point number 3.

3.       In the python console do the following:

>>> len(list(iface.mapCanvas().currentLayer().getFeatures()))
3
>>> len(list(iface.mapCanvas().currentLayer().dataProvider().getFeatures()))
4
>>> req = QgsFeatureRequest()
>>> req = req.setLimit(3)
>>> len(list(iface.mapCanvas().currentLayer().getFeatures(req)))
2
>>> len(list(iface.mapCanvas().currentLayer().dataProvider().getFeatures(req)))
3

If I access the features using the data provider with no request, I get too many features back. If I use a request when getting features directly from the layer, I get too few features back.

I guess the layer directly gives me the best result, but it chokes when the request is limited.

Who can I trust when getting features during an editing session? Or should I approach this in another way?

Regards, Casper

Using QGIS master (d3882d5) in Windows 7, x64
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160830/c84fe1e1/attachment-0001.html>


More information about the Qgis-developer mailing list