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
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
LETG
Rename bands
Commits
3fa10398
Commit
3fa10398
authored
Sep 17, 2021
by
PIERSON Julie
Browse files
launching from history ok even when some layers are not loaded
parent
87347d2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
+14
-13
MergeBandTableWidget.py
MergeBandTableWidget.py
+14
-7
merge_rename_bands_algorithm.py
merge_rename_bands_algorithm.py
+0
-6
No files found.
MergeBandTableWidget.py
View file @
3fa10398
...
@@ -149,20 +149,27 @@ class MergeBandTableWidget(BASE, WIDGET):
...
@@ -149,20 +149,27 @@ class MergeBandTableWidget(BASE, WIDGET):
# when launching alg from history in processing, setting parameters
# when launching alg from history in processing, setting parameters
def
setValue
(
self
,
value
):
def
setValue
(
self
,
value
):
QMessageBox
.
information
(
None
,
self
.
tr
(
'window name'
),
self
.
tr
(
'message'
))
self
.
bandClassTree
.
clear
()
self
.
bandClassTree
.
clear
()
# getting raster names
# getting raster names
param
=
value
.
split
(
';'
)
param
=
value
.
split
(
';'
)
param
=
[
i
.
split
(
','
)
for
i
in
param
]
param
=
[
i
.
split
(
','
)
for
i
in
param
]
rasterNames
=
[
i
[
0
]
for
i
in
param
]
rasterNames
=
[
i
[
0
]
for
i
in
param
]
QMessageBox
.
information
(
None
,
self
.
tr
(
'hop'
),
self
.
tr
(
str
(
param
)))
# keeping only loaded layers
rasterNames
=
[
i
for
i
in
rasterNames
if
len
(
QgsProject
.
instance
().
mapLayersByName
(
i
))
!=
0
]
# checking items in combobox
# checking items in combobox
self
.
multiLayers
.
setCheckedItems
(
rasterNames
)
self
.
multiLayers
.
setCheckedItems
(
rasterNames
)
# populating second column in table with band future name
# clearing table since rasters may not have been added in right order when checking items
bandNames
=
[
i
[
1
]
for
i
in
param
]
self
.
bandClassTree
.
clear
()
root
=
self
.
bandClassTree
.
invisibleRootItem
()
# for each raster
for
i
in
range
(
len
(
bandNames
)):
for
r
in
param
:
item
=
item
=
root
.
child
(
i
)
# if a raster is loaded
item
.
setText
(
1
,
bandNames
[
i
])
if
r
[
0
]
in
rasterNames
:
# populate columns in table
item
=
QTreeWidgetItem
()
item
.
setText
(
0
,
r
[
0
])
item
.
setText
(
1
,
r
[
1
])
self
.
bandClassTree
.
addTopLevelItem
(
item
)
# return a list each element for a table row
# return a list each element for a table row
# ['band 1, new name 1', 'band 2, new name 2']
# ['band 1, new name 1', 'band 2, new name 2']
...
...
merge_rename_bands_algorithm.py
View file @
3fa10398
...
@@ -114,9 +114,6 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
...
@@ -114,9 +114,6 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
input_param
=
ParameterMergeBandTable
.
tableValuesAsList
(
parameters
[
self
.
INPUT
])
input_param
=
ParameterMergeBandTable
.
tableValuesAsList
(
parameters
[
self
.
INPUT
])
output_raster_path
=
self
.
parameterAsOutputLayer
(
parameters
,
self
.
OUTPUT
,
context
)
output_raster_path
=
self
.
parameterAsOutputLayer
(
parameters
,
self
.
OUTPUT
,
context
)
message
=
'input_param : '
+
str
(
input_param
)
feedback
.
pushInfo
(
QCoreApplication
.
translate
(
'merge and rename'
,
message
))
# GETTING USEFUL PARAMETERS
# GETTING USEFUL PARAMETERS
# number of rows in table = number of bands to merge
# number of rows in table = number of bands to merge
...
@@ -135,9 +132,7 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
...
@@ -135,9 +132,7 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
rasterLayers
=
[
QgsProject
.
instance
().
mapLayersByName
(
i
)[
0
]
for
i
in
rasterNames
]
rasterLayers
=
[
QgsProject
.
instance
().
mapLayersByName
(
i
)[
0
]
for
i
in
rasterNames
]
rasterPaths
=
[
i
.
source
()
for
i
in
rasterLayers
]
rasterPaths
=
[
i
.
source
()
for
i
in
rasterLayers
]
# MERGING BANDS
# MERGING BANDS
merge_param
=
{
merge_param
=
{
'INPUT'
:
rasterPaths
,
'INPUT'
:
rasterPaths
,
'SEPARATE'
:
True
,
'SEPARATE'
:
True
,
...
@@ -159,7 +154,6 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
...
@@ -159,7 +154,6 @@ class MergeAndRenameAlgorithm(QgsProcessingAlgorithm):
new_name
=
band_table
[
band_number
][
index_oldname
]
new_name
=
band_table
[
band_number
][
index_oldname
]
band
.
SetDescription
(
new_name
)
band
.
SetDescription
(
new_name
)
# RETURNING RESULTS
# RETURNING RESULTS
# Return the results of the algorithm as a dictionary
# Return the results of the algorithm as a dictionary
...
...
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