Commit 0b640167 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

fixed default band selection issues

parent 22b01359
......@@ -854,14 +854,27 @@ class MapCanvas(QgsMapCanvas):
if isinstance(r, QgsMultiBandColorRenderer):
#newRenderer = QgsMultiBandColorRenderer(None, r.redBand(), r.greenBand(), r.blueBand())
newRenderer = cloneRenderer(r)
newRenderer = QgsMultiBandColorRenderer(None, r.redBand(), r.greenBand(), r.blueBand())
newRenderer.setRedContrastEnhancement(getCE(r.redBand()))
newRenderer.setGreenContrastEnhancement(getCE(r.greenBand()))
newRenderer.setBlueContrastEnhancement(getCE(r.blueBand()))
ceR = getCE(r.redBand())
ceG = getCE(r.greenBand())
ceB = getCE(r.blueBand())
if False:
vMin = min(ceR.minimumValue(), ceG.minimumValue(), ceB.minimumValue())
vMax = max(ceR.maximumValue(), ceG.maximumValue(), ceB.maximumValue())
for ce in [ceR, ceG, ceB]:
assert isinstance(ce, QgsContrastEnhancement)
ce.setMaximumValue(vMax)
ce.setMinimumValue(vMin)
newRenderer.setRedContrastEnhancement(ceR)
newRenderer.setGreenContrastEnhancement(ceG)
newRenderer.setBlueContrastEnhancement(ceB)
elif isinstance(r, QgsSingleBandPseudoColorRenderer):
newRenderer = r.clone()
newRenderer = cloneRenderer(r)
ce = getCE(newRenderer.band())
#stats = dp.bandStatistics(newRenderer.band(), QgsRasterBandStats.All, extent, 500)
......@@ -870,7 +883,12 @@ class MapCanvas(QgsMapCanvas):
newRenderer.setClassificationMin(ce.minimumValue())
shader.setMaximumValue(ce.maximumValue())
shader.setMinimumValue(ce.minimumValue())
elif isinstance(r, QgsSingleBandGrayRenderer):
newRenderer = cloneRenderer(r)
s = ""
elif isinstance(r, QgsPalettedRasterRenderer):
s = ""
#newRenderer = cloneRenderer(r)
if newRenderer is not None:
self.sigChangeSVRequest.emit(self, newRenderer)
......
This diff is collapsed.
......@@ -20,7 +20,7 @@
"""
# noinspection PyPep8Naming
import six, sys, os, gc, re, collections, site, inspect
import sys, os, gc, re, collections, site, inspect
from osgeo import gdal, ogr
from qgis import *
from qgis.core import *
......@@ -352,10 +352,10 @@ if __name__ == '__main__':
timeseriesviewer.DEBUG = True
#run tests
if False: gdal_qgis_benchmark()
if True: sandboxQgisBridge()
if False: sandboxQgisBridge()
if False: sandboxGui()
if False: sandboxTestdata()
if True: sandboxTestdata()
if False: sandboxDemo()
#close QGIS
qgsApp.exec_()
......
......@@ -658,7 +658,7 @@ def convertMetricUnit(value, u1, u2):
def bandClosestToWavelength(dataset, wl, wl_unit='nm'):
"""
Returns the band index of an image dataset closest to wavelength `wl`.
Returns the band index (!) of an image dataset closest to wavelength `wl`.
:param dataset: str | gdal.Dataset
:param wl: wavelength to search the closed band for
:param wl_unit: unit of wavelength. Default = nm
......@@ -683,6 +683,18 @@ def bandClosestToWavelength(dataset, wl, wl_unit='nm'):
pass
return 0
def cloneRenderer(renderer):
assert isinstance(renderer, QgsRasterRenderer)
cloned = renderer.clone()
#handle specific issues if cloning is not exactly the same
if isinstance(cloned, QgsSingleBandPseudoColorRenderer):
cloned.setClassificationMin(renderer.classificationMin())
cloned.setClassificationMax(renderer.classificationMax())
return cloned
def parseWavelength(dataset):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment