Skip to content

Commit

Permalink
Fixed auto fill the labeling buttoms from layer function, added anoth…
Browse files Browse the repository at this point in the history
…er way to compute the unique values if no xml color style is defined in the layer, among others fixes
  • Loading branch information
XavierCLL committed Dec 21, 2024
1 parent 9607972 commit 5992916
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
18 changes: 12 additions & 6 deletions gui/response_design_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def __init__(self, buttons_config):
self.setupUi(self)
self.buttons_config = buttons_config if buttons_config is not None else {}
# init with empty table
self.table_buttons = dict(zip(range(1, 301), [""] * 300))
self.table_buttons = dict(zip(range(1, 1001), [""] * 1000))
self.create_table()
#
self.tableBtnsConfig.itemClicked.connect(self.table_item_clicked)
Expand Down Expand Up @@ -837,14 +837,20 @@ def apply_auto_fill_from_thematic_map(self):
from AcATaMa.gui.acatama_dockwidget import AcATaMaDockWidget as AcATaMa
# clean the table
self.create_table()

# get the symbology table; pixel values, labels and colors from thematic map
symbology_table = get_symbology_table(AcATaMa.dockwidget.QCBox_ThematicMap.currentLayer())
symbology_table = get_symbology_table(AcATaMa.dockwidget.QCBox_ThematicMap.currentLayer(),
band=int(AcATaMa.dockwidget.QCBox_band_ThematicMap.currentText()))
nodata_value = get_nodata_format(AcATaMa.dockwidget.nodata_ThematicMap.text())

# create the buttons
for symbology_item in symbology_table:
for item_idx, symbology_item in enumerate(symbology_table):
value, label, color = symbology_item
self.tableBtnsConfig.item(value, 0).setText(label)
self.tableBtnsConfig.item(value, 1).setBackground(color)
self.tableBtnsConfig.item(value, 2).setText(str(value))
if value == nodata_value:
continue
self.tableBtnsConfig.item(item_idx, 0).setText(label)
self.tableBtnsConfig.item(item_idx, 1).setBackground(color)
self.tableBtnsConfig.item(item_idx, 2).setText(str(value))


FORM_CLASS, _ = uic.loadUiType(os.path.join(
Expand Down
8 changes: 8 additions & 0 deletions utils/others_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def get_pixel_values(layer, band):
pixel_values = []
for item in items:
pixel_values.append(int(item.get("value")))

# fallback to get the unique values if no xml color style is defined in the layer
if not pixel_values:
dataset = gdal_array.LoadFile(get_file_path_of_layer(layer))
if len(dataset.shape) == 3:
dataset = dataset[band - 1]
pixel_values = np.unique(dataset).tolist()

return pixel_values


Expand Down
7 changes: 6 additions & 1 deletion utils/qgis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ def unload_layer(layer_path):
QgsProject.instance().removeMapLayer(layer_loaded.id())


def get_symbology_table(raster_layer):
def get_symbology_table(raster_layer, band):
"""Get the symbology table with pixel value, label and Qcolor of raster layer
"""
from AcATaMa.core.map import get_xml_style

# check if the thematic map has a valid symbology else ask to apply an automatic classification
get_xml_style(raster_layer, band)

renderer = raster_layer.renderer()

if renderer.type() == 'singlebandpseudocolor':
Expand Down

0 comments on commit 5992916

Please sign in to comment.