<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#CCCCFF" text="#6633FF">
Hi all, <br>
<br>
I have some problems to apply new stretching values to my layer<br>
<br>
I have a function which allows to adapt the stretching of my image
without the raster layer properties dialog.<br>
<br>
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.<br>
<br>
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.<br>
<br>
Here is my stretching code :<br>
<br>
<blockquote type="cite"> print canvas<br>
print "layer :", theRasterLayer<br>
<br>
# type of layer : raster, vector, other<br>
typeOfLayer = theRasterLayer.type()<br>
<br>
dataProvider = theRasterLayer.dataProvider()<br>
<br>
# the layer has to be a raster layer<br>
if typeOfLayer == 1 :<br>
if (theRasterLayer.rasterType() == 0 ) and
theRasterLayer.renderer():<br>
[...]<br>
<br>
elif theRasterLayer.rasterType() == 2 and
theRasterLayer.renderer():<br>
min_red, max_red = values[0]<br>
min_green, max_green = values[1]<br>
min_blue, max_blue = values[2]<br>
<br>
redEnhancement = QgsContrastEnhancement(
dataProvider.dataType( 0 ) )<br>
greenEnhancement = QgsContrastEnhancement(
dataProvider.dataType( 1 ) )<br>
blueEnhancement = QgsContrastEnhancement(
dataProvider.dataType( 2 ) )<br>
#set stretch to min max<br>
redEnhancement.setMinimumValue( min_red )<br>
redEnhancement.setMaximumValue( max_red )<br>
greenEnhancement.setMinimumValue( min_green )<br>
greenEnhancement.setMaximumValue( max_green )<br>
blueEnhancement.setMinimumValue( min_blue )<br>
blueEnhancement.setMaximumValue( max_blue )<br>
redEnhancement.setContrastEnhancementAlgorithm(1)<br>
greenEnhancement.setContrastEnhancementAlgorithm(1)<br>
blueEnhancement.setContrastEnhancementAlgorithm(1)<br>
<br>
print "blue enhancement", blueEnhancement<br>
print "blue max", blueEnhancement.maximumValue()<br>
print "blue min", blueEnhancement.minimumValue()<br>
<br>
theRasterLayer.renderer().setRedContrastEnhancement(
redEnhancement)<br>
theRasterLayer.renderer().setGreenContrastEnhancement(
greenEnhancement )<br>
theRasterLayer.renderer().setBlueContrastEnhancement(
blueEnhancement)<br>
<br>
theRasterLayer.triggerRepaint()<br>
<br>
print theRasterLayer.renderer().blueContrastEnhancement()<br>
print
theRasterLayer.renderer().blueContrastEnhancement().minimumValue()<br>
print
theRasterLayer.renderer().blueContrastEnhancement().maximumValue()<br>
canvas.refresh()<br>
canvas.repaint()</blockquote>
<br>
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().<br>
<br>
I know :<br>
* both cases run this function.<br>
* 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)<br>
* these values are the good ones<br>
* they aren't displayed in the raster layer properties dialog<br>
* my raster layer source is ok<br>
* when i do these steps on the QGIS python console with the layer
iface.mapCanvas().currentLayer() which points to the same file, it
works<br>
<br>
<blockquote type="cite">layer = iface.mapCanvas().currentLayer()<br>
blue_en = QgsContrastEnhancement(
layer.dataProvider().dataType(2))<br>
blue_en.setMinimumValue(150)<br>
blue_en.setMaximumValue(350)<br>
blue_en.setContrastEnhancementAlgorithm(1)<br>
layer.renderer().setBlueContrastEnhancement(blue_en)<br>
layer.triggerRepaint()</blockquote>
<br>
What have I missed ?<br>
<br>
Thanks by advance, <br>
Alexia<br>
</body>
</html>