diff --git a/python/plugins/processing/algs/qgis/Relief.py b/python/plugins/processing/algs/qgis/Relief.py index c7e4e5b80f0..8eb64ac0fc9 100644 --- a/python/plugins/processing/algs/qgis/Relief.py +++ b/python/plugins/processing/algs/qgis/Relief.py @@ -75,6 +75,10 @@ class Relief(GeoAlgorithm): self.value = None return True + if value == '': + if not self.optional: + return False + if isinstance(value, str): self.value = value if value != '' else None else: @@ -100,11 +104,11 @@ class Relief(GeoAlgorithm): def colorsToString(colors): s = '' for c in colors: - s += '{:.2f}, {:.2f}, {:d}, {:d}, {:d};'.format(c[0], - c[1], - c[2], - c[3], - c[4]) + s += '{:f}, {:f}, {:d}, {:d}, {:d};'.format(c[0], + c[1], + c[2], + c[3], + c[4]) return s[:-1] self.addParameter(ParameterRaster(self.INPUT_LAYER, diff --git a/python/plugins/processing/algs/qgis/ReliefAuto.py b/python/plugins/processing/algs/qgis/ReliefAuto.py deleted file mode 100644 index 76575a9d6d4..00000000000 --- a/python/plugins/processing/algs/qgis/ReliefAuto.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -*************************************************************************** - ReliefAuto.py - --------------------- - Date : October 2016 - Copyright : (C) 2016 by Alexander Bruy - Email : alexander dot bruy at gmail dot com -*************************************************************************** -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -*************************************************************************** -""" - -__author__ = 'Alexander Bruy' -__date__ = 'October 2016' -__copyright__ = '(C) 2016, Alexander Bruy' - -# This will get replaced with a git SHA1 when you do a git archive - -__revision__ = '$Format:%H$' - -import os - -from qgis.PyQt.QtGui import QIcon - -from qgis.analysis import QgsRelief - -from processing.core.GeoAlgorithm import GeoAlgorithm -from processing.core.parameters import ParameterRaster -from processing.core.parameters import ParameterNumber -from processing.core.outputs import OutputRaster -from processing.core.outputs import OutputTable -from processing.tools import raster - -pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0] - - -class ReliefAuto(GeoAlgorithm): - - INPUT_LAYER = 'INPUT_LAYER' - Z_FACTOR = 'Z_FACTOR' - OUTPUT_LAYER = 'OUTPUT_LAYER' - FREQUENCY_DISTRIBUTION = 'FREQUENCY_DISTRIBUTION' - - def getIcon(self): - return QIcon(os.path.join(pluginPath, 'images', 'dem.png')) - - def defineCharacteristics(self): - self.name, self.i18n_name = self.trAlgorithm('Relief (automatic colors)') - self.group, self.i18n_group = self.trAlgorithm('Raster terrain analysis') - - self.addParameter(ParameterRaster(self.INPUT_LAYER, - self.tr('Elevation layer'))) - self.addParameter(ParameterNumber(self.Z_FACTOR, - self.tr('Z factor'), 1.0, 999999.99, 1.0)) - self.addOutput(OutputRaster(self.OUTPUT_LAYER, - self.tr('Relief'))) - self.addOutput(OutputTable(self.FREQUENCY_DISTRIBUTION, - self.tr('Frequency distribution'))) - - def processAlgorithm(self, progress): - inputFile = self.getParameterValue(self.INPUT_LAYER) - zFactor = self.getParameterValue(self.Z_FACTOR) - outputFile = self.getOutputValue(self.OUTPUT_LAYER) - frequencyDistribution = self.getOutputValue(self.FREQUENCY_DISTRIBUTION) - - outputFormat = raster.formatShortNameFromFileName(outputFile) - - relief = QgsRelief(inputFile, outputFile, outputFormat) - colors = relief.calculateOptimizedReliefClasses() - relief.setReliefColors(colors) - relief.setZFactor(zFactor) - relief.exportFrequencyDistributionToCsv(frequencyDistribution) - relief.processRaster(None) diff --git a/python/plugins/processing/algs/qgis/ui/ReliefColorsWidget.py b/python/plugins/processing/algs/qgis/ui/ReliefColorsWidget.py index 1004b69ece9..e577123fb57 100644 --- a/python/plugins/processing/algs/qgis/ui/ReliefColorsWidget.py +++ b/python/plugins/processing/algs/qgis/ui/ReliefColorsWidget.py @@ -239,11 +239,11 @@ class ReliefColorsWidget(BASE, WIDGET): rColors = self.reliefColors() colors = '' for c in rColors: - colors += '{:.2f}, {:.2f}, {:d}, {:d}, {:d};'.format(c.minElevation, - c.maxElevation, - c.color.red(), - c.color.green(), - c.color.blue()) + colors += '{:f}, {:f}, {:d}, {:d}, {:d};'.format(c.minElevation, + c.maxElevation, + c.color.red(), + c.color.green(), + c.color.blue()) return colors[:-1] diff --git a/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml b/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml index 26b2869ed67..e602489bac1 100644 --- a/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml +++ b/python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml @@ -1153,17 +1153,18 @@ tests: name: Relief (custom colors) params: AUTO_COLORS: false - COLORS: 85.00, 104.44, 7, 165, 144;104.44, 104.44, 12, 221, 162;104.44, 104.44, - 33, 252, 183;104.44, 104.44, 247, 252, 152;104.44, 104.44, 252, 196, 8;104.44, - 190.33, 252, 166, 15;190.33, 226.70, 175, 101, 15;226.70, 226.70, 255, 133, - 92;226.70, 243.00, 204, 204, 204 + COLORS: 85.000000, 104.436508, 7, 165, 144;104.436508, 104.436508, 12, 221, 162;104.436508, + 104.436508, 33, 252, 183;104.436508, 104.436508, 247, 252, 152;104.436508, 104.436508, + 252, 196, 8;104.436508, 190.333333, 252, 166, 15;190.333333, 226.698413, 175, + 101, 15;226.698413, 226.698413, 255, 133, 92;226.698413, 243.000000, 204, 204, + 204 INPUT_LAYER: name: dem.tif type: raster Z_FACTOR: 1.0 results: OUTPUT_LAYER: - hash: 6c79ec9b948c8e878aa490670e8a26a0b6efc5f9d162a0fff1042d80 + hash: 7fe0e0174185fd743e23760f33615adf10f771b4275f320db6f7f4f8 type: rasterhash # Case 1: Keep all fields