I am trying to create a for loop for coloring up multiple rasters simultaneously. I am able to do it for one layer, but trying to implement the for loop to do it for more than one layer is proving difficult.
from PyQt4 import QtGuiglob,os
lyr=QgsRasterLayer("rast_path="/home/user/Desktop/data/gsi/output/569600_angleoutput"
rasters=glob.glob(os.path.join(rast_path,"*le.tif"))
print(rasters)
for raster in rasters:
# (rastdir,"Angle"rastfile)=os.path.split(raster)
lyr=QgsRasterLayer(rasters,rastfile)
s=QgsRasterShader()
c=QgsColorRampShader()
c.setColorRampType(QgsColorRampShader.INTERPOLATED)
i=[]
i.append(QgsColorRampShader.ColorRampItem(-20,QtGui.QColor('#0c0101'),'-20'))
i.append(QgsColorRampShader.ColorRampItem(-15.1,QtGui.QColor('#ff0000'),'-15'))
i.append(QgsColorRampShader.ColorRampItem(-10,QtGui.QColor('#ff0000'),'-10'))
i.append(QgsColorRampShader.ColorRampItem(-5,QtGui.QColor('#ff0000'),'-5'))
i.append(QgsColorRampShader.ColorRampItem(0,QtGui.QColor('#ff0000'),'0'))
i.append(QgsColorRampShader.ColorRampItem(5,QtGui.QColor('#ff0000'),'5'))
i.append(QgsColorRampShader.ColorRampItem(10,QtGui.QColor('#ff0000'),'10'))
i.append(QgsColorRampShader.ColorRampItem(15,QtGui.QColor('#ff0000'),'15'))
i.append(QgsColorRampShader.ColorRampItem(15,QtGui.QColor('#0c0101'),'20'))
c.setColorRampItemList(i)
s.setRasterShaderFunction(c)
ps=QgsSingleBandPseudoColorRenderer(lyr.dataProvider(),1,s)
lyr raster.setRenderer(ps)
QgsMapLayerRegistry.instance().addMapLayer(lyr)
# qgis.utils.iface.addRasterLayer(raster,rastfile)