[Qgis-developer] Keep track of features in memory provider

Matthias Kuhn matthias.kuhn at gmx.ch
Mon Nov 18 11:58:04 PST 2013


On Mon 18 Nov 2013 19:36:22 CET, Radim Blazek wrote:
> On Mon, Nov 18, 2013 at 6:44 PM, Matthias Kuhn <matthias.kuhn at gmx.ch> wrote:
>> As far as I know, currently the most appropriate thing is to use
>> layer.dataProvider().addFeatures() and to skip the edit buffer.
>
> That is what I am doing, but QgsMemoryProvider::addFeatures()
> overwrites original feature id.

It will return a (list of) new feature with the real id:

status, features = l.dataProvider().addFeatures( feats )
features[0].id()


>
> Another issue with writing directly to provider is, that attribute
> table is not updated. So how to programmatically change features
> avoiding edit buffer?

I think we should rather fix this issue. I would very much like 
QgsVectorLayer to emit a signal, when it commits the features and 
changes their ids.

QgsVectorLayer::featureIdsChanged( QMap< QgsFeatureId, QgsFeatureId )

So you could connect to this and would not be forced to directly 
interact with the dataprovider.

Matthias

>
> Radim
>
>> But I
>> think that layers should broadcast information about changing feature
>> ids. This is not a problem unique to the memory provider.
>>
>> Matthias
>>
>> On Mon 18 Nov 2013 17:25:39 CET, Radim Blazek wrote:
>>> Is there a trick how to keep track of features added to memory provider?
>>>
>>> Say that feature with id is added to a memory provider. Original id is
>>> overwritten by the memory provider. How to access the feature in the
>>> provider by original id without additional attribute or hacks like
>>> counting mNextFeatureId outside the provider.
>>>
>>> Radim
>>> _______________________________________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>>




More information about the Qgis-developer mailing list