[Qgis-developer] featureAtId replacement

Denis Rouzaud denis.rouzaud at gmail.com
Mon Feb 11 22:16:10 PST 2013


On 02/11/2013 06:14 PM, Matthias Kuhn wrote:
> 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:
>>> I'd write:
>>>
>>> f = QgsFeature()
>>> if layer.getFeatures( QgsFeatureRequest().setFilterFid( 
>>> self.subset[i] ) ).nextFeature( f ):
>>>    return f
Thanks Jef!

>> 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?
+10 ;)

f = layer.getFeature( fid )
getFeatures( [fids] ).nextFeature( f )
  getFeatures( rect ).nextFeature( f )

I think these 3 would be really welcome!

Denis



More information about the Qgis-developer mailing list