# -*- coding: utf-8 -*- """ /*************************************************************************** RenameBands A QGIS plugin Rename and reorder raster bands Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ ------------------- begin : 2021-09-09 copyright : (C) 2021 by Julie Pierson email : julie.pierson@univ-brest.fr ***************************************************************************/ /*************************************************************************** * * * 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__ = 'Julie Pierson' __date__ = '2021-09-09' __copyright__ = '(C) 2021 by Julie Pierson' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' from qgis.PyQt.QtCore import QCoreApplication from qgis.core import (QgsProcessing, QgsProcessingAlgorithm, QgsProcessingParameterRasterLayer, QgsProcessingParameterRasterDestination) import processing class RenameBandsAlgorithm(QgsProcessingAlgorithm): """ This is an algorithm that takes a raster layer and rename and/or reorder its bands. """ # Constants used to refer to parameters and outputs. They will be # used when calling the algorithm from another algorithm, or when # calling from the QGIS console. OUTPUT = 'OUTPUT' INPUT = 'INPUT' def initAlgorithm(self, config): """ Here we define the inputs and output of the algorithm, along with some other properties. """ # input raster layer self.addParameter( QgsProcessingParameterRasterLayer( self.INPUT, self.tr('Input raster layer'), [QgsProcessing.TypeVectorAnyGeometry] ) ) # TODO # output raster layer self.addParameter( QgsProcessingParameterRasterDestination( 'OUTPUT', self.tr('Raster output') ) ) def processAlgorithm(self, parameters, context, feedback): """ Here is where the processing itself takes place. """ # Retrieve inputs and outputs input_raster = self.parameterAsRasterLayer(parameters, self.INPUT, context) output_path_raster = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) param_translate = {'INPUT': input_raster, 'TARGET_CRS':None, 'NODATA':None, 'COPY_SUBDATASETS':False, 'OPTIONS':'', 'EXTRA':'','DATA_TYPE':0, 'OUTPUT':output_path_raster } processing.run("gdal:translate", param_translate) # Return the results of the algorithm as a dictionary return {self.OUTPUT: output_path_raster} def name(self): """ Returns the algorithm name, used for identifying the algorithm. This string should be fixed for the algorithm, and must not be localised. The name should be unique within each provider. Names should contain lowercase alphanumeric characters only and no spaces or other formatting characters. """ return 'Rename Bands' def displayName(self): """ Returns the translated algorithm name, which should be used for any user-visible display of the algorithm name. """ return self.tr(self.name()) def group(self): """ Returns the name of the group this algorithm belongs to. This string should be localised. """ return self.tr(self.groupId()) def groupId(self): """ Returns the unique ID of the group this algorithm belongs to. This string should be fixed for the algorithm, and must not be localised. The group id should be unique within each provider. Group id should contain lowercase alphanumeric characters only and no spaces or other formatting characters. """ return '' def tr(self, string): return QCoreApplication.translate('Processing', string) def createInstance(self): return RenameBandsAlgorithm()