Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread David Marteau
Sorry, it has already been aswered, did not see the threads.


> Le 15 sept. 2017 à 16:46, David Marteau  a écrit :
> 
> Hi
> 
> If  FeatureIterator is a true iterator then use:
> 
> feature = next(FeatureIterator)
> 
> 
>> Le 15 sept. 2017 à 14:43, Andreas Neumann > > a écrit :
>> 
>> Hi,
>> 
>> While porting a project from QGIS 2x to 3x I came across a Python issue:
>> 
>> In QGIS 2.x I had a code like below working:
>> 
>> feature = FeatureIterator.next()
>> 
>> In QGIS 3x it says that object has no attribut next.
>> 
>> How do I access the first result of a feature iterator in QGIS 3?
>> 
>> I don't want to loop, because I know that my FeatureIterator always has just 
>> one result. I just want to access this first feature.
>> 
>> Thanks for your help,
>> 
>> Andreas
>> 
>> ___
>> QGIS-Developer mailing list
>> QGIS-Developer@lists.osgeo.org 
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread David Marteau
Hi

If  FeatureIterator is a true iterator then use:

feature = next(FeatureIterator)


> Le 15 sept. 2017 à 14:43, Andreas Neumann  a écrit :
> 
> Hi,
> 
> While porting a project from QGIS 2x to 3x I came across a Python issue:
> 
> In QGIS 2.x I had a code like below working:
> 
> feature = FeatureIterator.next()
> 
> In QGIS 3x it says that object has no attribut next.
> 
> How do I access the first result of a feature iterator in QGIS 3?
> 
> I don't want to loop, because I know that my FeatureIterator always has just 
> one result. I just want to access this first feature.
> 
> Thanks for your help,
> 
> Andreas
> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Andreas Neumann

Thanks Matthias for explaining about that. Good to know.

Andreas


On 15.09.2017 16:22, Matthias Kuhn wrote:

Hi Andreas,

that will be done automatically when the iterator scopes out or the last
feature is yielded.
There is normally no reason to care about this method.

Matthias

On 09/15/2017 04:04 PM, Andreas Neumann wrote:

Just a quick followup question.

I see that the QgsFeatureIterator has a close method.

Should Python authors care about closing an existing feature iterator or
would this be automatically done when the script stops executing?

Andreas


On 15.09.2017 15:48, Andreas Neumann wrote:

Hi Matteo and Matthias,

Thanks - that works fine. I did not know that this changed in Python 3.

All the poor QGIS book authors who need to rewrite their books ...
about this Python changes.

Helps a lot!

Andreas



On 15.09.2017 15:44, matteo wrote:

Hi Andreas,

if I'm not wrong the next method is not been removed, it is a python
3 *fix*

https://stackoverflow.com/questions/1073396/is-generator-next-visible-in-python-3-0


so instead of:

it = layer.getFeatures()
it.next()

just type

it = layer.getFeatures()
next(it)

Matteo
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Matthias Kuhn
Hi Andreas,

that will be done automatically when the iterator scopes out or the last
feature is yielded.
There is normally no reason to care about this method.

Matthias

On 09/15/2017 04:04 PM, Andreas Neumann wrote:
> Just a quick followup question.
> 
> I see that the QgsFeatureIterator has a close method.
> 
> Should Python authors care about closing an existing feature iterator or
> would this be automatically done when the script stops executing?
> 
> Andreas
> 
> 
> On 15.09.2017 15:48, Andreas Neumann wrote:
>> Hi Matteo and Matthias,
>>
>> Thanks - that works fine. I did not know that this changed in Python 3.
>>
>> All the poor QGIS book authors who need to rewrite their books ...
>> about this Python changes.
>>
>> Helps a lot!
>>
>> Andreas
>>
>>
>>
>> On 15.09.2017 15:44, matteo wrote:
>>> Hi Andreas,
>>>
>>> if I'm not wrong the next method is not been removed, it is a python
>>> 3 *fix*
>>>
>>> https://stackoverflow.com/questions/1073396/is-generator-next-visible-in-python-3-0
>>>
>>>
>>> so instead of:
>>>
>>> it = layer.getFeatures()
>>> it.next()
>>>
>>> just type
>>>
>>> it = layer.getFeatures()
>>> next(it)
>>>
>>> Matteo
>>> ___
>>> QGIS-Developer mailing list
>>> QGIS-Developer@lists.osgeo.org
>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>> ___
>> QGIS-Developer mailing list
>> QGIS-Developer@lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Matthias Kuhn
I was also thinking about that.
I would just miss this method because it's used so often and the
alternative approaches just require more typing.

+1 for this

On 09/15/2017 03:53 PM, Nathan Woodrow wrote:
> I think we could just implement out own next method to avoid that break
> would be easy enough.
> 
> On Fri, Sep 15, 2017 at 11:48 PM, Andreas Neumann  > wrote:
> 
> Hi Matteo and Matthias,
> 
> Thanks - that works fine. I did not know that this changed in Python 3.
> 
> All the poor QGIS book authors who need to rewrite their books ...
> about this Python changes.
> 
> Helps a lot!
> 
> Andreas
> 
> 
> 
> 
> On 15.09.2017 15:44, matteo wrote:
> 
> Hi Andreas,
> 
> if I'm not wrong the next method is not been removed, it is a
> python 3 *fix*
> 
> 
> https://stackoverflow.com/questions/1073396/is-generator-next-visible-in-python-3-0
> 
> 
> 
> so instead of:
> 
> it = layer.getFeatures()
> it.next()
> 
> just type
> 
> it = layer.getFeatures()
> next(it)
> 
> Matteo
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> 
> List info:
> https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> Unsubscribe:
> https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> 
> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org 
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> 
> 
> 
> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Andreas Neumann

Just a quick followup question.

I see that the QgsFeatureIterator has a close method.

Should Python authors care about closing an existing feature iterator or 
would this be automatically done when the script stops executing?


Andreas


On 15.09.2017 15:48, Andreas Neumann wrote:

Hi Matteo and Matthias,

Thanks - that works fine. I did not know that this changed in Python 3.

All the poor QGIS book authors who need to rewrite their books ... 
about this Python changes.


Helps a lot!

Andreas



On 15.09.2017 15:44, matteo wrote:

Hi Andreas,

if I'm not wrong the next method is not been removed, it is a python 
3 *fix*


https://stackoverflow.com/questions/1073396/is-generator-next-visible-in-python-3-0 



so instead of:

it = layer.getFeatures()
it.next()

just type

it = layer.getFeatures()
next(it)

Matteo
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Nathan Woodrow
I think we could just implement out own next method to avoid that break
would be easy enough.

On Fri, Sep 15, 2017 at 11:48 PM, Andreas Neumann 
wrote:

> Hi Matteo and Matthias,
>
> Thanks - that works fine. I did not know that this changed in Python 3.
>
> All the poor QGIS book authors who need to rewrite their books ... about
> this Python changes.
>
> Helps a lot!
>
> Andreas
>
>
>
>
> On 15.09.2017 15:44, matteo wrote:
>
>> Hi Andreas,
>>
>> if I'm not wrong the next method is not been removed, it is a python 3
>> *fix*
>>
>> https://stackoverflow.com/questions/1073396/is-generator-
>> next-visible-in-python-3-0
>>
>> so instead of:
>>
>> it = layer.getFeatures()
>> it.next()
>>
>> just type
>>
>> it = layer.getFeatures()
>> next(it)
>>
>> Matteo
>> ___
>> QGIS-Developer mailing list
>> QGIS-Developer@lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Andreas Neumann

Hi Matteo and Matthias,

Thanks - that works fine. I did not know that this changed in Python 3.

All the poor QGIS book authors who need to rewrite their books ... about 
this Python changes.


Helps a lot!

Andreas



On 15.09.2017 15:44, matteo wrote:

Hi Andreas,

if I'm not wrong the next method is not been removed, it is a python 3 *fix*

https://stackoverflow.com/questions/1073396/is-generator-next-visible-in-python-3-0

so instead of:

it = layer.getFeatures()
it.next()

just type

it = layer.getFeatures()
next(it)

Matteo
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Matthias Kuhn
I quickly googled for the reason for this

PEP 3114 (https://www.python.org/dev/peps/pep-3114/)

So next() was renamed to __next__() for consistency, because it's a
builtin method.

iterator.__next__() or next(iterator) should yield the same item.

Matthias

On 09/15/2017 03:44 PM, matteo wrote:
> Hi Andreas,
> 
> if I'm not wrong the next method is not been removed, it is a python 3 *fix*
> 
> https://stackoverflow.com/questions/1073396/is-generator-next-visible-in-python-3-0
> 
> so instead of:
> 
> it = layer.getFeatures()
> it.next()
> 
> just type
> 
> it = layer.getFeatures()
> next(it)
> 
> Matteo
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread matteo
Hi Andreas,

if I'm not wrong the next method is not been removed, it is a python 3 *fix*

https://stackoverflow.com/questions/1073396/is-generator-next-visible-in-python-3-0

so instead of:

it = layer.getFeatures()
it.next()

just type

it = layer.getFeatures()
next(it)

Matteo
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Matthias Kuhn
Hi Andreas,

that hasn't been a QGIS decision but a python3 one.

next(featureIterator) is the way proposed for python3. I am not sure
about the reasons for this change though.

Matthias

On 09/15/2017 03:40 PM, Andreas Neumann wrote:
> Hi,
> 
> Found out that I can access my first feature like:
> 
> feature = list(FeatureIterator)[0]
> 
> but not sure if this is recommended and efficient.
> 
> Why was the next() method of the feature iterator removed in QGIS 3? Is
> there a particular reason for that?
> 
> Thanks,
> 
> Andreas
> 
> 
> On 15.09.2017 14:43, Andreas Neumann wrote:
>> Hi,
>>
>> While porting a project from QGIS 2x to 3x I came across a Python issue:
>>
>> In QGIS 2.x I had a code like below working:
>>
>> feature = FeatureIterator.next()
>>
>> In QGIS 3x it says that object has no attribut next.
>>
>> How do I access the first result of a feature iterator in QGIS 3?
>>
>> I don't want to loop, because I know that my FeatureIterator always
>> has just one result. I just want to access this first feature.
>>
>> Thanks for your help,
>>
>> Andreas
>>
>> ___
>> QGIS-Developer mailing list
>> QGIS-Developer@lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] FeatureIterator Python question

2017-09-15 Thread Andreas Neumann

Hi,

While porting a project from QGIS 2x to 3x I came across a Python issue:

In QGIS 2.x I had a code like below working:

feature = FeatureIterator.next()

In QGIS 3x it says that object has no attribut next.

How do I access the first result of a feature iterator in QGIS 3?

I don't want to loop, because I know that my FeatureIterator always has 
just one result. I just want to access this first feature.


Thanks for your help,

Andreas

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer