Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Replace connected nodes edges #55

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions orm_importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ def _get_edge_speed(self, edge: Edge):
ways_b = set(self.ways[edge.node_b.name])
common_ways = ways_a.intersection(ways_b)
if len(common_ways) != 1:
return None
# The default 160 is arbitrary and set, so the following steps produce working output.
return 160
maxspeed = common_ways.pop().tags.get("maxspeed", None)
return int(maxspeed) if maxspeed else None
# The default 160 is arbitrary and set, so the following steps produce working output.
return int(maxspeed) if maxspeed else 160

def _should_add_edge(self, node_a: model.Node, node_b: model.Node, path: list[int]):
edge_not_present = not self.topology.get_edge_by_nodes(node_a, node_b)
Expand Down Expand Up @@ -181,8 +183,8 @@ def run(self, polygon):
if node_a and node_b and self._should_add_edge(node_a, node_b, path):
self.paths[(node_a, node_b)].append(path)
current_edge = model.Edge(node_a, node_b)
node_a.connected_nodes.append(node_b)
node_b.connected_nodes.append(node_a)
node_a.connected_edges.append(current_edge)
node_b.connected_edges.append(current_edge)
self.topology.add_edge(current_edge)
self._add_geo_nodes(path, current_edge)
current_edge.update_length()
Expand Down Expand Up @@ -236,9 +238,10 @@ def run(self, polygon):
candidate.lat, candidate.lon
).to_dbref()
new_edge = Edge(node, new_node)
new_edge.maximum_speed = 160
new_edge.update_length()
node.connected_nodes.append(new_node)
new_node.connected_nodes.append(node)
node.connected_edges.append(new_edge)
new_node.connected_edges.append(new_edge)
nodes_to_add.append(new_node)
self.topology.add_edge(new_edge)
break
Expand Down
9 changes: 5 additions & 4 deletions orm_importer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ def merge_edges(e1: model.Edge, e2: model.Edge, node_to_remove: model.Node):
print(str(e2.node_a.uuid) + " " + str(e2.node_b.uuid))
first_node = e1.node_a if e1.node_b == node_to_remove else e1.node_b
second_node = e2.node_a if e2.node_b == node_to_remove else e2.node_b
first_node.connected_nodes.remove(node_to_remove)
first_node.connected_nodes.append(second_node)
second_node.connected_nodes.remove(node_to_remove)
second_node.connected_nodes.append(first_node)
first_node.remove_edge_to_node(node_to_remove)
second_node.remove_edge_to_node(node_to_remove)
edge = Edge(first_node, second_node)
edge.maximum_speed = min(e1.maximum_speed, e2.maximum_speed)
first_node.connected_edges.append(edge)
second_node.connected_edges.append(edge)
edge.signals = e1.signals + e2.signals
edge.intermediate_geo_nodes = e1.intermediate_geo_nodes + e2.intermediate_geo_nodes
edge.update_length()
Expand Down
Loading