Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Possible Duplicate:
How to style a layer from console?

I'm trying to set the styles for a vector layer by loading the .qml file in the python console. The qml-style file contains all categories and symbols needed, but I can not find the right function to load the qml file. The QgsCategorizedSymbolRendererV2::create(domElement) seems to be not available in the python console (QGIS 1.8.0). Is myRenderer.load(doc.documentElement()) the right function to use?

Thank you!


#load the xml
xmlfile = QtCore.QFile("qgis-layer-style.qml")
doc = QtXml.QDomDocument( "Categories" ) 
if | QtCore.QIODevice.Text) == 0:
    print "cannot open file"
if doc.setContent( xmlfile ) == 0:
    print "no xml content"

# creating a new renderer
myRenderer = QgsCategorizedSymbolRendererV2('',[])
# here myRenderer has still no categories!

# assign myRenderer to the active layer
layer = qgis.utils.iface.activeLayer()
share|improve this question

marked as duplicate by underdark Sep 14 '12 at 8:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

I have used this function from within a plugin. You could try it from the python console:

In my plugin I use it like this:


share|improve this answer
Thank you! That's working and is easier, too! – greenland Sep 14 '12 at 8:25
looking in the source I also found layer.readSymbology(myDocRoot,errmsg) which also works fine and has a xml-element as parameter. – greenland Sep 14 '12 at 8:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.