Commit 2d725296 authored by PIERSON Julie's avatar PIERSON Julie
Browse files

bit of cleaning up

parent ceebba1d
......@@ -136,6 +136,7 @@ class BandTableWidget(BASE, WIDGET):
if item:
row = [item.text(0), item.text(1), item.text(2)]
band_names.append(row)
QMessageBox.information(None, self.tr('tralala'), self.tr(str(band_names)))
return band_names
def setLayer(self, layer):
......
......@@ -55,7 +55,8 @@ class ParameterBandTable(QgsProcessingParameterDefinition):
# getting output values as a list, 1st element for layer then one element for each row :
# ['/path/to/layer.tif', 'band 1, red, green', 'band 2, blue, red', 'bande 3, green, blue']
# ['/path/to/layer.tif', 'band 1, old name 1, new name 1', 'band 2, old name 2, new name 2']
# (see BandTableWidget.py to change this)
@staticmethod
def tableValuesAsList(value):
if value is None:
......@@ -114,29 +115,24 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
input_param = ParameterBandTable.tableValuesAsList(parameters[self.INPUT])
output_raster_path = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
# # GETTING USEFUL PARAMETERS
# GETTING USEFUL PARAMETERS
input_raster = input_param[0]
input_raster_path = input_param[0]
band_data = input_param[1:]
# number of rows in table
nb_row = len(band_data)
# # number of columns in table
# nb_col = len(band_data[0].split(','))
# index of column used for band order
index_bandorder = 0
# index of column used for band description
index_banddesc = 2
# index of column used for old band name
index_oldname = 1
# index of column used for new band name
index_newname = 2
# transform band_table in a nested list, with 1 element per band, and name and order of each band
# [['band 1', 1], ['band 2', 2], ['band 3', 3]]
band_table = [i.split(',') for i in band_data]
# getting input raster path
input_raster_path = input_raster
# read raster with gdal
input_raster = gdal.Open(input_raster)
# REORDERING BANDS
......@@ -150,31 +146,22 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
# RENAMING BANDS
# # get number of bands of input raster
# nbands = input_raster.RasterCount
# get number of rows in table
nb_row = len(band_table)
# # check if band number = row count in band_table
# if nbands != nb_row:
# message = 'Number of rows in table is different from number of bands in input raster'
# feedback.reportError(QCoreApplication.translate('Rename bands', message))
# return{}
# # reorder band table so that bands are in same order as in output raster
# sorted_band_table = sorted(band_table, key = lambda x: x[index_bandorder])
# iterate over each band to set its description using table input
for band_number in range(nb_row):
band = output_raster.GetRasterBand(band_number + 1)
band.SetDescription(band_table[band_number][index_banddesc])
new_name = band_table[band_number][index_newname]
# if no new name was set, use old name
if new_name == '':
new_name = band_table[band_number][index_oldname]
band.SetDescription(new_name)
# RETURNING RESULTS
# Return the results of the algorithm as a dictionary
#return {self.OUTPUT: output_raster_path}
return {'input_param' : input_param}
return {self.OUTPUT: output_raster_path}
def name(self):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment