Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
LETG
Rename bands
Commits
7cff2732
Commit
7cff2732
authored
Sep 13, 2021
by
PIERSON Julie
Browse files
checking input parameters
parent
fc4681c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
rename_bands_algorithm.py
rename_bands_algorithm.py
+13
-3
No files found.
rename_bands_algorithm.py
View file @
7cff2732
...
...
@@ -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
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment