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 "simple modification" (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 "frozen" to allow for stability.<br>
<br>I've tried to see if OGR already provides some way to handle metadata but this doesn'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"><<a href="mailto:b.rowlingson@lancaster.ac.uk">b.rowlingson@lancaster.ac.uk</a>></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>
You can do this, depending on how much control you have of the layer<br>
loading process...<br>
<br>
Python lets you add attributes to just about any object. So if you<br>
create a new menu option 'Load My Special Layer' 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 = "hello world". 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've violated their object...<br>
<br>
So you can subclass QgsVectorLayer to keep them happy. You do (something like):<br>
<br>
class SpecialLayer(QgsVectorLayer):<br>
def __init__(self,file):<br>
QgsVectorLayer.__init__(self,file)<br>
def setFnord(self,value):<br>
self.fnord=value<br>
<br>
BUT (and it'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>
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't exist.<br>
<br>
A possibility is to save it in the project settings (see QgsProject)<br>
which is separate from the layers. I'm thinking about this for the<br>
thing I'm working on.<br>
<font color="#888888"><br>
Barry<br>
</font></blockquote></div><br>