[Qgis-developer] Layer-level metadata

Florian El Ahdab felahdab at gmail.com
Tue Feb 3 14:39:43 EST 2009


Hi Barry.

Thanks for your quick answer and your ideas.

Your solution was already in my mind. Thanks for confirming my idea.

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.

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...)

Ticket https://trac.osgeo.org/qgis/ticket/1399 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...

Thanks a lot.
Florian

On Tue, Feb 3, 2009 at 6:58 PM, Barry Rowlingson <
b.rowlingson at lancaster.ac.uk> wrote:

>
>  You can do this, depending on how much control you have of the layer
> loading process...
>
>  Python lets you add attributes to just about any object. So if you
> create a new menu option 'Load My Special Layer' which lets the user
> choose a shapefile or other data source, you can create a
> QgsVectorLayer and then set something on it. Load a vector layer and
> then try this in the python console: l = iface.mapCanvas().layer(0)
> followed by l.fnord = "hello world". The .fnord attribute is now set,
> and other python code can check for presence of this. Any decent
> object-oriented programmer would throw up at this point at the way
> you've violated their object...
>
>  So you can subclass QgsVectorLayer to keep them happy. You do (something
> like):
>
> class SpecialLayer(QgsVectorLayer):
>   def __init__(self,file):
>      QgsVectorLayer.__init__(self,file)
>   def setFnord(self,value):
>       self.fnord=value
>
>  BUT (and it's a big but) none of this gets saved in project files.
> You could write a writeXML method on your layer which could save the
> metadata, but when it is read back Qgis will just create a plain
> QgsVectorLayer and throw away your extra information.
>
>  It would be nice to have a userMetadata object saved and restored
> with layers which would be some key-value structure accessible to
> Python and C++. At the moment such a thing doesn't exist.
>
>  A possibility is to save it in the project settings (see QgsProject)
> which is separate from the layers. I'm thinking about this for the
> thing I'm working on.
>
> Barry
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090203/3bf11240/attachment.html


More information about the Qgis-developer mailing list