Commit 7cff2732 authored by PIERSON Julie's avatar PIERSON Julie
Browse files

checking input parameters

parent fc4681c0
......@@ -92,23 +92,33 @@ class RenameBandsAlgorithm(QgsProcessingAlgorithm):
input_raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
band_table = self.parameterAsMatrix(parameters, self.TABLE, context)
# number of columns in table is used later on, change it here if necessary
nb_col = 2
# get input raster path
raster_path = input_raster.source()
# read raster with gdal
raster_gdal = gdal.Open(raster_path)
# get number of bands
nbands = raster_gdal.RasterCount
# TODO : check if band number = row number in band_table
# get number of rows in table
nrows = len(band_table) / nb_col
# check if band number = row count in band_table
if nbands != nrows:
message = 'Number of rows in table is different from number of bands in input raster'
feedback.reportError(QCoreApplication.translate('Rename bands', message))
return{}
# 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]]
nb_col = 2
band_table = [band_table[n:n+nb_col] for n in range(0, len(band_table), nb_col)]
# iterate over each band to set its description
# iterate over each band to set its description using table input
for band_number in range(nbands):
band = raster_gdal.GetRasterBand(band_number + 1)
band.SetDescription(band_table[band_number][0])
# set band order using table input
# Return the results of the algorithm as a dictionary
return {}
......
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