[Qgis-developer] featureAtId replacement
Martin Dobias
wonder.sk at gmail.com
Mon Feb 11 08:50:29 PST 2013
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)
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
More information about the Qgis-developer
mailing list