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

2016-08-31 Thread CABO
Hi Matthias and Nyall,

Thanks for your comments. 

I've created the issue: http://hub.qgis.org/issues/15505

Regards, Casper

-Original Message-
From: Qgis-developer [mailto:qgis-developer-boun...@lists.osgeo.org] On Behalf 
Of Nyall Dawson
Sent: 31. august 2016 01:09
To: Matthias Kuhn
Cc: qgis-developer
Subject: Re: [Qgis-developer] Python and strange results using 
layer(.dataProvider()).getFeatures(...)

On 30 August 2016 at 23:52, Matthias Kuhn <matth...@opengis.ch> wrote:
> Hi Casper
>
> On 08/30/2016 02:59 PM, Casper Børgesen (CABO) wrote:
>> Hi Nathan
>>
>>
>>
>> Thanks for clarifying that, I’ll try to put my faith in the layer. My 
>> question is then, why does the layer only respond with 2 features 
>> when I ask it for max 3 features, since 4 – 1 = 3?
>>
>
> I guess (no verification done) that in the background the limit is 
> forwarded to the dataprovider which returns 3 features from which 1 is 
> filtered out by the layer so only 2 remain.
>
> Please report this as a bug. I'm not sure if an action will be taken, 
> most of the "fixes" to this which I can think of defeat the purpose of 
> sending as few requests as possible to the database, but on the other 
> hand, this situation here can really lead to confusion.

I'd say something like this could work. In QgsVectorLayerFeatureIterator:
- take the feature request limit for mProviderRequest
- if deleted features are present in the edit buffer, add the number of deleted 
features to the limit in mProviderRequest
- if changed feature attributes are present, and the request is an expression 
based request, add the number of changed features to the limit (could be 
smarter here and check which attributes are required by the filter + which have 
changed)
- if geometry changes are present and a filter rect is in place then add the 
number of geometry changes to the limit

That would still gain us most of the benefits of feature limits + handle this 
case, and the only penalty is present when the bug would otherwise show itself.

Nyall



>
> Matthias
> ___
> Qgis-developer mailing list
> Qgis-developer@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

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

2016-08-30 Thread Matthias Kuhn
Hi Casper

On 08/30/2016 02:59 PM, Casper Børgesen (CABO) wrote:
> Hi Nathan
> 
>  
> 
> Thanks for clarifying that, I’ll try to put my faith in the layer. My
> question is then, why does the layer only respond with 2 features when I
> ask it for max 3 features, since 4 – 1 = 3?
> 

I guess (no verification done) that in the background the limit is
forwarded to the dataprovider which returns 3 features from which 1 is
filtered out by the layer so only 2 remain.

Please report this as a bug. I'm not sure if an action will be taken,
most of the "fixes" to this which I can think of defeat the purpose of
sending as few requests as possible to the database, but on the other
hand, this situation here can really lead to confusion.

Matthias
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

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

2016-08-30 Thread CABO
Hi Nathan

Thanks for clarifying that, I’ll try to put my faith in the layer. My question 
is then, why does the layer only respond with 2 features when I ask it for max 
3 features, since 4 – 1 = 3?

Does it find 3 features, determine that one of them has been deleted and only 
returns the two living features?`
Regards, Casper

From: Nathan Woodrow [mailto:madman...@gmail.com]
Sent: 30. august 2016 14:50
To: Casper Børgesen (CABO)
Cc: QGIS Developer Mailing List
Subject: Re: [Qgis-developer] Python and strange results using 
layer(.dataProvider()).getFeatures(...)

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) 
<c...@niras.dk<mailto:c...@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@lists.osgeo.org<mailto:Qgis-developer@lists.osgeo.org>
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

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

2016-08-30 Thread Nathan Woodrow
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) 
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@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

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

2016-08-30 Thread CABO
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@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer