1

I want to create a custom raster color ramp using pyqgis in a standalone app.

I have found some examples about this task, for example:

s=QgsRasterShader()
c=QgsColorRampShader()
c.setColorRampType(QgsColorRampShader.INTERPOLATED)
i=[]
i.append(QgsColorRampShader.ColorRampItem(30,QtGui.QColor('#d7191c'),'400'))
i.append(QgsColorRampShader.ColorRampItem(150,QtGui.QColor('#fdae61'),'900')) 
c.setColorRampItemList(i)
s.setRasterShaderFunction(c)
ps=QgsSingleBandPseudoColorRenderer(lyr.dataProvider(),1,s)
lyr.setRenderer(ps)
QgsMapLayerRegistry.instance().addMapLayer(lyr)

That code works fine in python console but I have some questions. How can I save that image with new color ramp to a new image (with new colors) in a standalone app?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.