Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
implement preference for number of digits of values to display on map…
Browse files Browse the repository at this point in the history
…, related to prefereneces issues #104 and #123
  • Loading branch information
PaulDudaRESPEC committed Aug 9, 2019
1 parent 0930719 commit aff01e0
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 17 deletions.
42 changes: 36 additions & 6 deletions src/ui/EPANET/frmMainEPANET.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ def update_thematic_map(self):

if self.model_layers.nodes_layers:
selected_attribute = self.cboMapNodes.currentText()

num_figs = 2
if selected_attribute in self.project_settings.node_numerical_preferences:
precision = self.project_settings.node_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

attribute = None
setting_index = self.cboMapNodes.currentIndex()
if setting_index < 4:
Expand Down Expand Up @@ -360,13 +367,21 @@ def update_thematic_map(self):
if color_by:
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_node_min,
self.thematic_node_max)
self.thematic_node_max,
number_of_digits=num_figs)
else:
self.map_widget.set_default_point_renderer(layer)
layer.triggerRepaint()

if self.model_layers.links_layers:
selected_attribute = self.cboMapLinks.currentText()

num_figs = 2
if selected_attribute in self.project_settings.link_numerical_preferences:
precision = self.project_settings.link_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

attribute = None
setting_index = self.cboMapLinks.currentIndex()
if setting_index < 6:
Expand Down Expand Up @@ -414,7 +429,8 @@ def update_thematic_map(self):
if color_by:
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_link_min,
self.thematic_link_max)
self.thematic_link_max,
number_of_digits=num_figs)
else:
self.map_widget.set_default_line_renderer(layer, do_labels=False)
layer.triggerRepaint()
Expand All @@ -433,6 +449,13 @@ def update_thematic_map_time(self):

if self.model_layers.nodes_layers:
selected_attribute = self.cboMapNodes.currentText()

num_figs = 2
if selected_attribute in self.project_settings.node_numerical_preferences:
precision = self.project_settings.node_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

setting_index = self.cboMapNodes.currentIndex()
color_by = {}
if setting_index >= 4 and self.output: # Look for attribute to color by in the output
Expand All @@ -454,12 +477,12 @@ def update_thematic_map_time(self):
self.thematic_node_min,
self.thematic_node_max,
self.map_widget.layer_styles[layer.id()],
True, None, do_label)
True, None, do_label, num_figs)
else:
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_node_min,
self.thematic_node_max,
None, True, None, do_label)
None, True, None, do_label, num_figs)
self.annotate_layername(selected_attribute, "node", layer)
else:
if len(self.project.all_nodes()) > 300:
Expand All @@ -469,6 +492,13 @@ def update_thematic_map_time(self):

if self.model_layers.links_layers:
selected_attribute = self.cboMapLinks.currentText()

num_figs = 2
if selected_attribute in self.project_settings.link_numerical_preferences:
precision = self.project_settings.link_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

setting_index = self.cboMapLinks.currentIndex()
color_by = {}
if setting_index >= 6 and self.output: # Look for attribute to color by in the output
Expand Down Expand Up @@ -508,14 +538,14 @@ def update_thematic_map_time(self):
self.thematic_link_max,
self.map_widget.layer_styles[layer.id()],
self.chkDisplayFlowDir.isChecked(),
color_by_flow, do_label)
color_by_flow, do_label, num_figs)
else:
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_link_min,
self.thematic_link_max,
None,
self.chkDisplayFlowDir.isChecked(),
color_by_flow, do_label)
color_by_flow, do_label, num_figs)
self.annotate_layername(selected_attribute, "link", layer)
else:
self.map_widget.set_default_line_renderer(layer, do_label)
Expand Down
62 changes: 53 additions & 9 deletions src/ui/SWMM/frmMainSWMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ def update_thematic_map(self):

if self.model_layers.subcatchments and self.model_layers.subcatchments.isValid():
selected_attribute = self.cboMapSubcatchments.currentText()

num_figs = 2
if selected_attribute in self.project_settings.subcatchment_numerical_preferences:
precision = self.project_settings.subcatchment_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

attribute = None
setting_index = self.cboMapSubcatchments.currentIndex()
if setting_index < 6:
Expand Down Expand Up @@ -706,13 +713,20 @@ def update_thematic_map(self):
self.map_widget.applyGraduatedSymbologyStandardMode(self.model_layers.subcatchments, color_by,
self.thematic_subcatchment_min,
self.thematic_subcatchment_max,
do_label=False)
do_label=False, number_of_digits=num_figs)
else:
self.map_widget.set_default_polygon_renderer(self.model_layers.subcatchments)
self.model_layers.subcatchments.triggerRepaint()

if self.model_layers.nodes_layers:
selected_attribute = self.cboMapNodes.currentText()

num_figs = 2
if selected_attribute in self.project_settings.node_numerical_preferences:
precision = self.project_settings.node_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

attribute = None
setting_index = self.cboMapNodes.currentIndex()
if setting_index < 2:
Expand Down Expand Up @@ -748,13 +762,21 @@ def update_thematic_map(self):
if color_by:
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_node_min,
self.thematic_node_max)
self.thematic_node_max,
number_of_digits=num_figs)
else:
self.map_widget.set_default_point_renderer(layer)
layer.triggerRepaint()

if self.model_layers.links_layers:
selected_attribute = self.cboMapLinks.currentText()

num_figs = 2
if selected_attribute in self.project_settings.link_numerical_preferences:
precision = self.project_settings.link_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

attribute = None
setting_index = self.cboMapLinks.currentIndex()
if setting_index < 3:
Expand Down Expand Up @@ -818,7 +840,8 @@ def update_thematic_map(self):
display_flow_dir = self.chkDisplayFlowDir.isChecked()
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_link_min,
self.thematic_link_max)
self.thematic_link_max,
number_of_digits=num_figs)
else:
self.map_widget.set_default_line_renderer(layer, do_labels=False)
layer.triggerRepaint()
Expand All @@ -843,6 +866,13 @@ def update_thematic_map_time(self):
if self.model_layers.subcatchments and self.model_layers.subcatchments.isValid():
layer = self.model_layers.subcatchments
selected_attribute = self.cboMapSubcatchments.currentText()

num_figs = 2
if selected_attribute in self.project_settings.subcatchment_numerical_preferences:
precision = self.project_settings.subcatchment_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

setting_index = self.cboMapSubcatchments.currentIndex()
color_by = {}
if setting_index >= 6 and self.output: # Look for attribute to color by in the output
Expand All @@ -864,12 +894,12 @@ def update_thematic_map_time(self):
self.thematic_node_min,
self.thematic_node_max,
self.map_widget.layer_styles[layer.id()],
True, None, do_label)
True, None, do_label, num_figs)
else:
self.map_widget.applyGraduatedSymbologyStandardMode(self.model_layers.subcatchments, color_by,
self.thematic_subcatchment_min,
self.thematic_subcatchment_max,
None, True, None, do_label)
None, True, None, do_label, num_figs)
self.annotate_layername(selected_attribute, "subcatchment", layer)
#self.map_widget.LegendDock.setVisible(True)
else:
Expand All @@ -879,6 +909,13 @@ def update_thematic_map_time(self):

if self.model_layers.nodes_layers:
selected_attribute = self.cboMapNodes.currentText()

num_figs = 2
if selected_attribute in self.project_settings.node_numerical_preferences:
precision = self.project_settings.node_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

setting_index = self.cboMapNodes.currentIndex()
color_by = {}
if setting_index >= 2 and self.output: # Look for attribute to color by in the output
Expand All @@ -902,12 +939,12 @@ def update_thematic_map_time(self):
self.thematic_node_min,
self.thematic_node_max,
self.map_widget.layer_styles[layer.id()],
True, None, do_label)
True, None, do_label, num_figs)
else:
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_node_min,
self.thematic_node_max,
None, True, None, do_label)
None, True, None, do_label, num_figs)
self.annotate_layername(selected_attribute, "node", layer)
else:
do_label = True
Expand All @@ -919,6 +956,13 @@ def update_thematic_map_time(self):

if self.model_layers.links_layers:
selected_attribute = self.cboMapLinks.currentText()

num_figs = 2
if selected_attribute in self.project_settings.link_numerical_preferences:
precision = self.project_settings.link_numerical_preferences[selected_attribute]
if precision > -1:
num_figs = precision

setting_index = self.cboMapLinks.currentIndex()
color_by = {}
if setting_index > 3 and self.output: # Look for attribute to color by in the output
Expand Down Expand Up @@ -955,14 +999,14 @@ def update_thematic_map_time(self):
self.thematic_link_max,
self.map_widget.layer_styles[layer.id()],
self.chkDisplayFlowDir.isChecked(),
color_by_flow)
color_by_flow, number_of_digits=num_figs)
else:
self.map_widget.applyGraduatedSymbologyStandardMode(layer, color_by,
self.thematic_link_min,
self.thematic_link_max,
None,
self.chkDisplayFlowDir.isChecked(),
color_by_flow)
color_by_flow, number_of_digits=num_figs)
self.annotate_layername(selected_attribute, "link", layer)
else:
do_label = True
Expand Down
5 changes: 3 additions & 2 deletions src/ui/map_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,8 @@ def validatedDefaultSymbol(geometryType):

@staticmethod
def applyGraduatedSymbologyStandardMode(layer, color_by, min=None, max=None,
arenderer=None, aflow_dir=True, acolor_by_flow=None, do_label=True):
arenderer=None, aflow_dir=True, acolor_by_flow=None, do_label=True,
number_of_digits=2):
provider = layer.dataProvider()
calculate_min_max = False
if min is None or max is None:
Expand All @@ -1307,7 +1308,7 @@ def applyGraduatedSymbologyStandardMode(layer, color_by, min=None, max=None,
geom = feature.geometry()
val = color_by[feature_name]
vfi = feature.fieldNameIndex('value')
provider.changeAttributeValues({feature.id(): {vfi: round(val, 2)}})
provider.changeAttributeValues({feature.id(): {vfi: round(val, number_of_digits)}})
# provider.changeAttributeValues({feature.id() : {1 : '100, 255, 50'}})
# feature[1] = val
if do_flowdir:
Expand Down

0 comments on commit aff01e0

Please sign in to comment.