Skip to content

Commit

Permalink
Merge pull request #92 from napakalas/issue-#91
Browse files Browse the repository at this point in the history
handling possible error due to empty dictionary (#91)
  • Loading branch information
dbrnz authored Oct 10, 2024
2 parents 2d8f7f5 + 34c0e66 commit 4c10fa0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mapmaker/routing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,14 @@ def get_centreline_from_containing_features(start_dict, end_dict, feature_ids: s
len(se_dict.get('used', {}) & set(properties['subgraph'].nodes)) == 0:
candidates= {(n, s):self.__flatmap.get_feature(n).geometry.centroid.distance(self.__flatmap.get_feature(s).geometry.centroid)
for n, s in itertools.product(se_dict.get('used', set()), properties['subgraph'].nodes)}
if len(selected:=min(candidates, key=candidates.get)) == 2:
for n, s in itertools.product(se_dict['node'], used_nodes):
if (n, s) in connectivity_graph.edges:
edge_dict = connectivity_graph.edges[(n, s)]
tmp_edge_dicts[selected] = edge_dict
new_direct_edges.update([selected])
break
if len(candidates) > 0:
if len(selected:=min(candidates, key=candidates.get)) == 2:
for n, s in itertools.product(se_dict['node'], used_nodes):
if (n, s) in connectivity_graph.edges:
edge_dict = connectivity_graph.edges[(n, s)]
tmp_edge_dicts[selected] = edge_dict
new_direct_edges.update([selected])
break

for ends, list_path_nodes in graph_utils.connected_paths(connectivity_graph).items():
for path_nodes in list_path_nodes:
Expand Down Expand Up @@ -1075,7 +1076,8 @@ def get_centreline_from_containing_features(start_dict, end_dict, feature_ids: s
if (nf:=self.__map_feature(n)) is not None and (sf:=self.__map_feature(s)) is not None:
candidates[(n,s)] = nf.geometry.centroid.distance(sf.geometry.centroid)
tmp_edge_dicts[(n,s)] = edge_dict
new_direct_edges.update([min(candidates, key=candidates.get)]) # type: ignore
if len(candidates) > 0:
new_direct_edges.update([min(candidates, key=candidates.get)]) # type: ignore
elif ((p_dict:=connectivity_graph.nodes[prev_node])['type'] == 'feature' and
(n_dict:=connectivity_graph.nodes[node])['type'] == 'feature'):
if ((pf:=list(p_dict.get('features'))[0].id) in route_graph.nodes and
Expand Down

0 comments on commit 4c10fa0

Please sign in to comment.