Hi all,

I have some problems to apply new stretching values to my layer

I have a function which allows to adapt the stretching of my image without the raster layer properties dialog.

When I open an image with my plugin, I display it on the canvas, I open my own histograms, and I can move the min max stretch of the 3 displayed bands.

It works well. But, when i save the project, i reopen it, I want to change the image stretching, it does nothing. The values are set, but it seems that the layer renderer is not updated.

Here is my stretching code :

    print canvas
    print "layer :", theRasterLayer

    # type of layer : raster, vector, other
    typeOfLayer = theRasterLayer.type()

    dataProvider = theRasterLayer.dataProvider()

    # the layer has to be a raster layer
    if typeOfLayer == 1 :
if (theRasterLayer.rasterType() == 0 ) and theRasterLayer.renderer():
[...]

elif theRasterLayer.rasterType() == 2 and theRasterLayer.renderer():
            min_red, max_red = values[0]
            min_green, max_green = values[1]
            min_blue, max_blue = values[2]

redEnhancement = QgsContrastEnhancement( dataProvider.dataType( 0 ) ) greenEnhancement = QgsContrastEnhancement( dataProvider.dataType( 1 ) ) blueEnhancement = QgsContrastEnhancement( dataProvider.dataType( 2 ) )
            #set stretch to min max
            redEnhancement.setMinimumValue( min_red )
            redEnhancement.setMaximumValue( max_red )
            greenEnhancement.setMinimumValue( min_green )
            greenEnhancement.setMaximumValue( max_green )
            blueEnhancement.setMinimumValue( min_blue )
            blueEnhancement.setMaximumValue( max_blue )
            redEnhancement.setContrastEnhancementAlgorithm(1)
            greenEnhancement.setContrastEnhancementAlgorithm(1)
            blueEnhancement.setContrastEnhancementAlgorithm(1)

            print "blue enhancement", blueEnhancement
            print "blue max", blueEnhancement.maximumValue()
            print "blue min", blueEnhancement.minimumValue()

theRasterLayer.renderer().setRedContrastEnhancement( redEnhancement) theRasterLayer.renderer().setGreenContrastEnhancement( greenEnhancement ) theRasterLayer.renderer().setBlueContrastEnhancement( blueEnhancement)

        theRasterLayer.triggerRepaint()

        print theRasterLayer.renderer().blueContrastEnhancement()
print theRasterLayer.renderer().blueContrastEnhancement().minimumValue() print theRasterLayer.renderer().blueContrastEnhancement().maximumValue()
    canvas.refresh()
    canvas.repaint()

In my case, the canvas, is the main canvas, I have checked I work on the good one comparing the print canvas and the python console with iface.mapCanvas().

I know :
* both cases run this function.
* the minimum and maximum values of contrast enhancement are the same in my two prints (before and after the setXContrastEnhancement) (so the theRasterLayer.renderer().blueContrastEnhancement() seems to be well set)
* these values are the good ones
* they aren't displayed in the raster layer properties dialog
* my raster layer source is ok
* when i do these steps on the QGIS python console with the layer iface.mapCanvas().currentLayer() which points to the same file, it works

layer = iface.mapCanvas().currentLayer()
blue_en = QgsContrastEnhancement( layer.dataProvider().dataType(2))
blue_en.setMinimumValue(150)
blue_en.setMaximumValue(350)
blue_en.setContrastEnhancementAlgorithm(1)
layer.renderer().setBlueContrastEnhancement(blue_en)
layer.triggerRepaint()

What have I missed ?

Thanks by advance,
Alexia
_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to