Skip to content
Snippets Groups Projects
widgets.py 40.3 KiB
Newer Older
  • Learn to ignore specific revisions
  •             r = QgsMultiBandColorRenderer(None,
                    ui.sliderRed.value(), ui.sliderGreen.value(), ui.sliderBlue.value())
    
                i = self.ui.comboBoxContrastEnhancement.currentIndex()
                alg = self.ui.comboBoxContrastEnhancement.itemData(i)
    
                if alg == QgsContrastEnhancement.NoEnhancement:
                    r.setRedContrastEnhancement(None)
                    r.setGreenContrastEnhancement(None)
                    r.setBlueContrastEnhancement(None)
                else:
                    rgbEnhancements = []
                    for i in range(3):
                        e = QgsContrastEnhancement(self.sensor.bandDataType)
    
                        minmax = [float(self.multiBandMinValues[i].text()), float(self.multiBandMaxValues[i].text())]
                        cmin = min(minmax)
                        cmax = max(minmax)
                        e.setMinimumValue(cmin)
                        e.setMaximumValue(cmax)
    
                        e.setContrastEnhancementAlgorithm(alg)
                        rgbEnhancements.append(e)
                    r.setRedContrastEnhancement(rgbEnhancements[0])
                    r.setGreenContrastEnhancement(rgbEnhancements[1])
                    r.setBlueContrastEnhancement(rgbEnhancements[2])
    
            if ui.stackedWidget.currentWidget() == ui.pageSingleBand:
                r = QgsSingleBandPseudoColorRenderer(None, ui.sliderSingleBand.value(), None)
    
                minmax = [float(ui.tbSingleBandMin.text()), float(ui.tbSingleBandMax.text())]
                cmin = min(minmax)
                cmax = max(minmax)
    
                r.setClassificationMin(cmin)
                r.setClassificationMax(cmax)
                colorRamp = self.ui.cbSingleBandColorRamp.currentColorRamp()
    
                # fix: QGIS 3.0 constructor
                shaderFunc = QgsColorRampShader(cmin, cmax)
                shaderFunc.setColorRampType(self.currentComboBoxItem(ui.cbSingleBandColorRampType))
                shaderFunc.setClip(True)
                nSteps = 10
                colorRampItems = []
    
                for i in range(nSteps + 1):
                    f = float(i) / nSteps
                    color = colorRamp.color(f)
                    value = cmin + diff * f
                    colorRampItems.append(QgsColorRampShader.ColorRampItem(value, color))
                shaderFunc.setColorRampItemList(colorRampItems)
                shader = QgsRasterShader()
    
                shader.setMaximumValue(cmax)
                shader.setMinimumValue(cmin)
    
                shader.setRasterShaderFunction(shaderFunc)
                r.setShader(shader)
    
    class PropertyDialogUI(QDialog, loadUIFormClass(PATH_SETTINGSDIALOG_UI)):
    
        def __init__(self, parent=None):
            super(PropertyDialogUI, self).__init__(parent)
            self.setupUi(self)
    
    
    
    if __name__ == '__main__':
        import site, sys
        #add site-packages to sys.path as done by enmapboxplugin.py
    
        from timeseriesviewer import DIR_SITE_PACKAGES
        site.addsitedir(DIR_SITE_PACKAGES)
    
        #prepare QGIS environment
        if sys.platform == 'darwin':
            PATH_QGS = r'/Applications/QGIS.app/Contents/MacOS'
            os.environ['GDAL_DATA'] = r'/usr/local/Cellar/gdal/1.11.3_1/share'
        else:
            # assume OSGeo4W startup
            PATH_QGS = os.environ['QGIS_PREFIX_PATH']
        assert os.path.exists(PATH_QGS)
    
        qgsApp = QgsApplication([], True)
        QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns')
        QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns/qgis')
        qgsApp.setPrefixPath(PATH_QGS, True)
        qgsApp.initQgis()
    
        #run tests
        #d = AboutDialogUI()
        #d.show()
    
        d = PropertyDialogUI()
        d.exec_()
        #close QGIS
        qgsApp.exec_()
        qgsApp.exitQgis()