Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am new to the QGIS python console. I am trying to load a raster layer from the console, set the crs and a specific style from a qml file.

layerPath = os.path.join(raster_dir,raster_name)
fileInfo = QtCore.QFileInfo(layerPath)
baseName = fileInfo.baseName()
layer = QgsRasterLayer(layerPath, baseName)

I would like to set up the projection info and then load it to QGIS

QgsMapLayerRegistry.instance().addMapLayer(layer)

I do have a grey raster on the windows. How can I set up the qml file to load ?

Thanks for your help

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

use QgsMapLayer::loadNamedStyle

uri = "/home/user/style.qml"
layer.loadNamedStyle(uri) 
share|improve this answer
    
Thank for your help, Unfortunatly, it does'nt not work. How shall write the uri ? –  Renaud Jun 6 '12 at 9:12
    
Thank you for your help, However I cannot manage to get it working.When I run the following command –  Renaud Jun 6 '12 at 9:31
    
Thank you for your help, However I cannot manage to get it working.When I run the following command uri = "file:///home/renaud/palette.qml";layer.loadNamedStyle(uri) I get the error message : Style not found in databased. Thank for your help ? How do I jump line in this post ? –  Renaud Jun 6 '12 at 9:37
    
looks like theUri is a bit misleading - using the plain filename should work (ie. /home/renaud/palette.qml) –  jef Jun 6 '12 at 13:25
    
Thank You, It is working fine now. One more time, keep it simple is the best way ! –  Renaud Jun 7 '12 at 17:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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