[Qgis-developer] Usefull methods

vatto mauricio.dev at gmail.com
Wed Dec 10 09:10:00 EST 2008


I've written some methods to work with layers' names. I found the usefull and 
usually being used in every script I make. Shouldn't these stuff be a default 
in the API? Well, the python code is here. It shouldn't be hard to translate 
do C++.

def listLayers(self,layertype):
    layersmap=QgsMapLayerRegistry.instance().mapLayers()
    layerslist=[]
    for (name,layer) in layersmap.iteritems():
        if (layertype==layer.type()):
            layerslist.append(layer.name())
    return layerslist

def getLayerByName(self,layerName):
    layersmap=QgsMapLayerRegistry.instance().mapLayers()
    for (name,layer) in layersmap.iteritems():
        if (layerName==layer.name()):
            return layer 

Maurício de Paulo


More information about the Qgis-developer mailing list