[Qgis-developer] Memory data provider persistence

Chris Crook ccrook at linz.govt.nz
Mon Nov 29 14:54:35 EST 2010

Hi All

I'm looking for ideas/suggestions/comments on the memory data provider.

A while ago I raised a ticket http://trac.osgeo.org/qgis/ticket/2487, the essence of which is that if you save and reload a project nothing should have changed, but if you have a layer supported by a memory data provider then its contents get lost. 

In the ticket I suggested that the user should be warned on saving, and the layers not included in the project file.  That way at least you don't end up with empty layers.

I'm now coming to a different point of view, which is that it would make much more sense to save the data for the memory provider into the project file.  Basically this would involve the following:

1) On saving a project, the data would be serialized into an element, probably in the map layer element in the project file.  For example it could be a <data...> node.  This could include the attribute definitions as well as each feature, or perhaps better the attribute definitions could be encoded into the datasourceUri.

2) On loading the data node would be read to repopulate the provider.  

Also useful, but not directly related to this, would be to enhance the layer "Save as" function so that when it is invoked on a memory layer the memory layer is replaced with the saved version, maybe as an option.

In terms of implementation I think this could involve the following components:

1) Add virtual functions to the QgsDataProvider writeDataXML(QDomNode &layerNode) and readDataXml( QDomNode &layerNode) with default empty implementations.  Call these functions in the QgsVectorLayer writeXml and readXml functions. 

2) Add a signal dataSectionDirty() to the QgsDataProvider, so that edits to the data in a memory provider could render the project dirty.  This signal would ultimately need to be linked to the project dirty() function.

2) Add serialization/deserialisation functions to QgsFeature, and QgsAttributeMap to read and write the data for a memory provider.  There would be a question with this as to how much to structure the data for "human" consumption.  Should the geometry be WKT or WKB?  Should the attributes be simply serialized into a QDataStream and then encoded into XML, or should they be dumped more intelligently as structured XML elements.

3) Implement the readDataXml(), writeDataXml() functions in QgsMemoryProvider, and fire the dataSectionDirty() signal whenever the data is changed.

I guess the main issue with this is that the project file would potentially get a lot larger when large memory data sets are added (eg Contour plugin).  But I think that is better than silently losing the work held in a memory data provider.

Any thoughts on these suggestions??


This message contains information, which is confidential and may be subject to legal privilege. 
If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.

Thank you.

More information about the Qgis-developer mailing list