Exemplo n.º 1
0
    def processAlgorithm(self, feedback):
        inputFile = self.getParameterValue(self.INPUT_LAYER)
        zFactor = self.getParameterValue(self.Z_FACTOR)
        automaticColors = self.getParameterValue(self.AUTO_COLORS)
        colors = self.getParameterValue(self.COLORS)
        outputFile = self.getOutputValue(self.OUTPUT_LAYER)
        frequencyDistribution = self.getOutputValue(self.FREQUENCY_DISTRIBUTION)

        outputFormat = raster.formatShortNameFromFileName(outputFile)

        relief = QgsRelief(inputFile, outputFile, outputFormat)

        if automaticColors:
            reliefColors = relief.calculateOptimizedReliefClasses()
        else:
            if colors is None:
                raise GeoAlgorithmExecutionException(
                    self.tr('Specify relief colors or activate "Generate relief classes automatically" option.'))

            reliefColors = []
            for c in colors.split(';'):
                v = c.split(',')
                color = QgsRelief.ReliefColor(QColor(int(v[2]), int(v[3]), int(v[4])),
                                              float(v[0]),
                                              float(v[1]))
                reliefColors.append(color)

        relief.setReliefColors(reliefColors)
        relief.setZFactor(zFactor)
        relief.exportFrequencyDistributionToCsv(frequencyDistribution)
        relief.processRaster(None)
Exemplo n.º 2
0
    def on_btnAuto_clicked(self):
        if self.layer is None:
            return

        relief = QgsRelief(self.layer, system.getTempFilename(), 'GTiff')
        colors = relief.calculateOptimizedReliefClasses()
        self.populateColors(colors)
Exemplo n.º 3
0
    def processAlgorithm(self, parameters, context, feedback):
        inputFile = self.parameterAsRasterLayer(parameters, self.INPUT, context).source()
        zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
        automaticColors = self.parameterAsBoolean(parameters, self.AUTO_COLORS, context)
        outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        frequencyDistribution = self.parameterAsFileOutput(parameters, self.FREQUENCY_DISTRIBUTION, context)

        outputFormat = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])

        relief = QgsRelief(inputFile, outputFile, outputFormat)

        if automaticColors:
            reliefColors = relief.calculateOptimizedReliefClasses()
        else:
            colors = ParameterReliefColors.valueToColors(parameters[self.COLORS])
            if colors is None or len(colors) == 0:
                raise QgsProcessingException(
                    self.tr('Specify relief colors or activate "Generate relief classes automatically" option.'))

            reliefColors = []
            for c in colors:
                v = c.split(',')
                color = QgsRelief.ReliefColor(QColor(int(v[2]), int(v[3]), int(v[4])),
                                              float(v[0]),
                                              float(v[1]))
                reliefColors.append(color)

        relief.setReliefColors(reliefColors)
        relief.setZFactor(zFactor)
        if frequencyDistribution:
            relief.exportFrequencyDistributionToCsv(frequencyDistribution)
        relief.processRaster(feedback)

        return {self.OUTPUT: outputFile, self.FREQUENCY_DISTRIBUTION: frequencyDistribution}
Exemplo n.º 4
0
    def on_btnAuto_clicked(self):
        if self.layer is None:
            return

        relief = QgsRelief(self.layer, system.getTempFilename(), 'GTiff')
        colors = relief.calculateOptimizedReliefClasses()
        self.populateColors(colors)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 def reliefColors(self):
     colors = []
     for i in range(self.reliefClassTree.topLevelItemCount()):
         item = self.reliefClassTree.topLevelItem(i)
         if item:
             c = QgsRelief.ReliefColor(item.background(2).color(),
                                       float(item.text(0)),
                                       float(item.text(1)))
             colors.append(c)
     return colors
Exemplo n.º 7
0
    def processAlgorithm(self, parameters, context, feedback):
        inputFile = exportRasterLayer(
            self.parameterAsRasterLayer(parameters, self.INPUT, context))
        zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
        automaticColors = self.parameterAsBool(parameters, self.AUTO_COLORS,
                                               context)
        outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT,
                                                 context)
        frequencyDistribution = self.parameterAsFileOutput(
            parameters, self.FREQUENCY_DISTRIBUTION, context)

        outputFormat = QgsRasterFileWriter.driverForExtension(
            os.path.splitext(outputFile)[1])

        relief = QgsRelief(inputFile, outputFile, outputFormat)

        if automaticColors:
            reliefColors = relief.calculateOptimizedReliefClasses()
        else:
            colors = ParameterReliefColors.valueToColors(
                parameters[self.COLORS])
            if colors is None or len(colors) == 0:
                raise QgsProcessingException(
                    self.
                    tr('Specify relief colors or activate "Generate relief classes automatically" option.'
                       ))

            reliefColors = []
            for c in colors:
                v = c.split(',')
                color = QgsRelief.ReliefColor(
                    QColor(int(v[2]), int(v[3]), int(v[4])), float(v[0]),
                    float(v[1]))
                reliefColors.append(color)

        relief.setReliefColors(reliefColors)
        relief.setZFactor(zFactor)
        if frequencyDistribution:
            relief.exportFrequencyDistributionToCsv(frequencyDistribution)
        relief.processRaster(feedback)

        return {
            self.OUTPUT: outputFile,
            self.FREQUENCY_DISTRIBUTION: frequencyDistribution
        }
Exemplo n.º 8
0
    def processAlgorithm(self, feedback):
        inputFile = self.getParameterValue(self.INPUT_LAYER)
        zFactor = self.getParameterValue(self.Z_FACTOR)
        automaticColors = self.getParameterValue(self.AUTO_COLORS)
        colors = self.getParameterValue(self.COLORS)
        outputFile = self.getOutputValue(self.OUTPUT_LAYER)
        frequencyDistribution = self.getOutputValue(
            self.FREQUENCY_DISTRIBUTION)

        outputFormat = raster.formatShortNameFromFileName(outputFile)

        relief = QgsRelief(inputFile, outputFile, outputFormat)

        if automaticColors:
            reliefColors = relief.calculateOptimizedReliefClasses()
        else:
            if colors is None:
                raise GeoAlgorithmExecutionException(
                    self.
                    tr('Specify relief colors or activate "Generate relief classes automatically" option.'
                       ))

            reliefColors = []
            for c in colors.split(';'):
                v = c.split(',')
                color = QgsRelief.ReliefColor(
                    QColor(int(v[2]), int(v[3]), int(v[4])), float(v[0]),
                    float(v[1]))
                reliefColors.append(color)

        relief.setReliefColors(reliefColors)
        relief.setZFactor(zFactor)
        relief.exportFrequencyDistributionToCsv(frequencyDistribution)
        relief.processRaster(None)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    def processAlgorithm(self, parameters, context, feedback):
        inputFile = self.parameterAsRasterLayer(parameters, self.INPUT, context).source()
        zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
        automaticColors = self.parameterAsBoolean(parameters, self.AUTO_COLORS, context)
        outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        frequencyDistribution = self.parameterAsFileOutput(parameters, self.FREQUENCY_DISTRIBUTION, context)

        outputFormat = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])

        relief = QgsRelief(inputFile, outputFile, outputFormat)

        if automaticColors:
            reliefColors = relief.calculateOptimizedReliefClasses()
        else:
            colors = ParameterReliefColors.valueToColors(parameters[self.COLORS])
            if colors is None or len(colors) == 0:
                raise QgsProcessingException(
                    self.tr('Specify relief colors or activate "Generate relief classes automatically" option.'))

            reliefColors = []
            for c in colors:
                v = c.split(',')
                color = QgsRelief.ReliefColor(QColor(int(v[2]), int(v[3]), int(v[4])),
                                              float(v[0]),
                                              float(v[1]))
                reliefColors.append(color)

        relief.setReliefColors(reliefColors)
        relief.setZFactor(zFactor)
        if frequencyDistribution:
            relief.exportFrequencyDistributionToCsv(frequencyDistribution)
        res = relief.processRaster(feedback)
        if res == 1:
            raise QgsProcessingException(self.tr('Can not open input file.'))
        elif res == 2:
            raise QgsProcessingException(self.tr('Can not get GDAL driver for output file.'))
        elif res == 3:
            raise QgsProcessingException(self.tr('Can not create output file.'))
        elif res == 4:
            raise QgsProcessingException(self.tr('Can not get input band.'))
        elif res == 5:
            raise QgsProcessingException(self.tr('Can not create output bands.'))
        elif res == 6:
            raise QgsProcessingException(self.tr('Output raster size is too small (at least 3 rows needed).'))
        elif res == 7:
            feedback.pushInfo(self.tr('Cancelled.'))

        return {self.OUTPUT: outputFile, self.FREQUENCY_DISTRIBUTION: frequencyDistribution}