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

Nathan Woodrow madmanwoo at gmail.com
Tue Aug 30 05:49:30 PDT 2016


If you haven't saved the layer after you did the delete the provider still
thinks there is 4 features. The layer itself and the edit buffer sit above
the data provider.

Generally you should trust the layer as it knows the state of the edit
buffer.

On Tue, Aug 30, 2016 at 10:32 PM, Casper Børgesen (CABO) <CABO at niras.dk>
wrote:

> 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
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160830/68dbfdec/attachment.html>


More information about the Qgis-developer mailing list