[Qgis-developer] featureAtId replacement

Matthias Kuhn matthias.kuhn at gmx.ch
Mon Feb 11 09:14:14 PST 2013


On 02/11/2013 05:50 PM, Martin Dobias wrote:
> On Mon, Feb 11, 2013 at 5:23 PM, Jürgen E. <jef at norbit.de> wrote:
>> Hi Denis,
>>
>> On Mon, 11. Feb 2013 at 15:20:54 +0100, Denis Rouzaud wrote:
>>> which quite heavier than the previous
>>>
>>> f = QgsFeature
>>> if layer.featureAtId(self.subset[i],f):
>>>     return f
>>> Is there anything I missed? Anything lighter to write?
>> I'd write:
>>
>> f = QgsFeature()
>> if layer.getFeatures( QgsFeatureRequest().setFilterFid( self.subset[i] ) ).nextFeature( f ):
>>    return f
> I would like to add a convenience QgsFeatureRequest constructors that
> would save people some typing - one for filtering by FID, another for
> filtering by rectangle, so it would get a bit lighter:
> layer.getFeatures( QgsFeatureRequest( fid ) ).nextFeature(f)
> -or-
> f = layer.getFeatures( QgsFeatureRequest( fid ) ).next()
> (StopIteration exception would be thrown if the FID wouldn't exist)
>
> I have been thinking also about providing convenience getFeatures()
> call, for even shorter syntax:
> layer.getFeatures( fid ).nextFeature(f)
I would welcome short-hands for common use-cases.
The only thing is, that for layer.getFeatures (plural) passing an array 
of id's seems more natural to me, while layer.getFeature( fid ) returns 
one feature only.

>
> For a direct replacement of featureAtId() calls I have thought also
> about adding getFeature() convenience call, that would return first
> feature of a request:
> f = layer.getFeature( fid )
>
> Opinions?
>
> Regards
> Martin
Matthias


More information about the Qgis-developer mailing list