[Qgis-developer] QgsMapLayerRegistry.mapLayers() not available in Python Bindings

Martin Dobias wonder.sk at gmail.com
Fri Jan 11 05:57:11 EST 2008

On Jan 11, 2008 11:01 AM, Düster Horst <Horst.Duester at bd.so.ch> wrote:
> With Python I want to get all avalilable map layers from my current project.
> I tried to do this with
> layerCollection = QgsMapLayerRegistry().instance().mapLayers()
> It doesn't work. I took a look into qgsmaplayerregistry.sip and found out
> that the method mapLayers() is not wrapped until now. What is to do to wrap
> this method. Does exists a workareound to retrieve all project layers.


this function isn't wrapped so far because mapLayers() uses std::map
container which should be replaced with QMap instead. It's not a lot
of work, I'll do it probably soon.
Please note that theoretically QgsMapLayerRegistry can contain also
layers which are not part of the project (e.g. when using
georeferencer plugin it adds temporarily a layer to the registry).

In fact there is currently no way how to directly access all project's
layers correctly, since map canvas doesn't keep list of all layers
(only those which are visible) and it's not possible to access legend
from the plugin as it's not part of QGIS libraries :-/

One workaround would be to save the project and then use legend's
nodes to parse the list of layers, which is, well, quite inconvenient.
We should definitely do something with this. I guess for now wrapping
mapLayers() would do it...


More information about the Qgis-developer mailing list