Hi Barry.<br><br>Thanks for your quick answer and your ideas.<br><br>Your solution was already in my mind. Thanks for confirming my idea. <br><br>Your last point is particularly interesting because as you said, it would be nice that the metadata are saved with the layer. I think that a &quot;simple modification&quot; (meaning not a profound rewriting of the current API) could allow this feature to be added either to QgsMapLayer or to QgsVectorLayer or even in the QgsVectorDataProvider class... Bu I know the API is currently &quot;frozen&quot; to allow for stability.<br>
<br>I&#39;ve tried to see if OGR already provides some way to handle metadata but this doesn&#39;t seem to be the case (It could have been a partial solution...)<br><br>Ticket <a href="https://trac.osgeo.org/qgis/ticket/1399">https://trac.osgeo.org/qgis/ticket/1399</a> was opened 3 months ago about this particular question. I would like to know if anybody from the core developers can give me directions about this particular problem. Although I am not sure I can develop this, I would need some wider point of view so as to start looking in the right direction...<br>
<br>Thanks a lot.<br>Florian<br><br><div class="gmail_quote">On Tue, Feb 3, 2009 at 6:58 PM, Barry Rowlingson <span dir="ltr">&lt;<a href="mailto:b.rowlingson@lancaster.ac.uk">b.rowlingson@lancaster.ac.uk</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
&nbsp;You can do this, depending on how much control you have of the layer<br>
loading process...<br>
<br>
&nbsp;Python lets you add attributes to just about any object. So if you<br>
create a new menu option &#39;Load My Special Layer&#39; which lets the user<br>
choose a shapefile or other data source, you can create a<br>
QgsVectorLayer and then set something on it. Load a vector layer and<br>
then try this in the python console: l = iface.mapCanvas().layer(0)<br>
followed by l.fnord = &quot;hello world&quot;. The .fnord attribute is now set,<br>
and other python code can check for presence of this. Any decent<br>
object-oriented programmer would throw up at this point at the way<br>
you&#39;ve violated their object...<br>
<br>
&nbsp;So you can subclass QgsVectorLayer to keep them happy. You do (something like):<br>
<br>
class SpecialLayer(QgsVectorLayer):<br>
 &nbsp; def __init__(self,file):<br>
 &nbsp; &nbsp; &nbsp;QgsVectorLayer.__init__(self,file)<br>
 &nbsp; def setFnord(self,value):<br>
 &nbsp; &nbsp; &nbsp; self.fnord=value<br>
<br>
&nbsp;BUT (and it&#39;s a big but) none of this gets saved in project files.<br>
You could write a writeXML method on your layer which could save the<br>
metadata, but when it is read back Qgis will just create a plain<br>
QgsVectorLayer and throw away your extra information.<br>
<br>
&nbsp;It would be nice to have a userMetadata object saved and restored<br>
with layers which would be some key-value structure accessible to<br>
Python and C++. At the moment such a thing doesn&#39;t exist.<br>
<br>
&nbsp;A possibility is to save it in the project settings (see QgsProject)<br>
which is separate from the layers. I&#39;m thinking about this for the<br>
thing I&#39;m working on.<br>
<font color="#888888"><br>
Barry<br>
</font></blockquote></div><br>