[processing] use full precision for elevation values

remove unused file
This commit is contained in:
Alexander Bruy 2016-12-19 09:48:42 +02:00
parent c3e3ba6b49
commit f4f86cad63
4 changed files with 20 additions and 95 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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]

View File

@ -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