How to display a RGB raster on QGIS with no enhancement with Python Console

المشرف العام

Administrator
طاقم الإدارة
I'm working with a RGB raster on QGIS 2.6.1, on a Windows 7 machine.

I need to set the Contrast Enhancement option to No Enhancement with the Python Console (not through the Layer Properties window). I have developed a simple script, inspired by this discussion: QGIS Scripting problem updating contrast enhancements for raster layers using bandStatistics

layer = iface.activeLayer() renderer = layer.renderer() ContrastEnhancement = QgsContrastEnhancement.NoEnhancement for Band in range(3): if Band == 0: myBand = layer.renderer().redBand() elif Band == 1: myBand = layer.renderer().greenBand() elif Band == 2: myBand = layer.renderer().blueBand() myType = layer.renderer().dataType(myBand) myEnhancement = QgsContrastEnhancement(myType) myEnhancement.setContrastEnhancementAlgorithm(ContrastEnhancement,True) if Band == 0: layer.renderer().setRedContrastEnhancement(myEnhancement) elif Band == 1: layer.renderer().setGreenContrastEnhancement(myEnhancement) elif Band == 2: layer.renderer().setBlueContrastEnhancement(myEnhancement) layer.triggerRepaint() Unfortunately, it does not work and the layer becomes not visible. It seems that it is not handling correctly the min/max values of the bands. Any suggestion? Thanks!



أكثر...
 
أعلى