Skip to content

Commit fc84ee7

Browse files
Merge pull request #63 from simulate-digital-rail/yaramo2
Yaramo 2
2 parents c9b434a + 45b8ef2 commit fc84ee7

File tree

4 files changed

+1412
-506
lines changed

4 files changed

+1412
-506
lines changed

orm_importer/importer.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from yaramo import model
99
from yaramo.edge import Edge
1010
from yaramo.geo_node import Wgs84GeoNode
11-
from yaramo.geo_point import Wgs84GeoPoint
1211
from yaramo.topology import Topology
1312

1413
from orm_importer.utils import (
@@ -94,6 +93,9 @@ def _get_next_top_node(self, node, edge: "tuple[str, str]", path):
9493
for edge in distinct_edges:
9594
if edge[0] in way._node_ids and edge[1] in way._node_ids:
9695
return self._get_next_top_node(node_to, edge, path)
96+
raise Exception(
97+
f"{len(distinct_edges)}Could not determine next edge to follow for node {node_to_id}."
98+
)
9799
raise Exception(f"Could not determine next edge to follow for node {node_to_id}.")
98100

99101
next_edge = distinct_edges[0]
@@ -102,20 +104,22 @@ def _get_next_top_node(self, node, edge: "tuple[str, str]", path):
102104
def _add_geo_nodes(self, path, top_edge: Edge):
103105
for idx, node_id in enumerate(path):
104106
node = self.node_data[node_id]
105-
if idx == 0 or is_signal(node):
107+
if idx == 0 or is_signal(node, self.graph):
106108
continue
107-
top_edge.intermediate_geo_nodes.append(Wgs84GeoNode(node.lat, node.lon).to_dbref())
109+
top_edge.intermediate_geo_nodes.append(
110+
Wgs84GeoNode(node.lat, node.lon, data_source="osm")
111+
)
108112

109113
def _add_signals(self, path, edge: model.Edge, node_before, node_after):
110114
# append node and next_tope_node to path as they could also be signals (e.g. buffer stop)
111115
for node_id in [int(edge.node_a.name), *path, int(edge.node_b.name)]:
112116
node = self.node_data[node_id]
113-
if is_signal(node):
114-
signal_geo_point = Wgs84GeoPoint(node.lat, node.lon).to_dbref()
117+
if is_signal(node, self.graph):
118+
signal_geo_node = Wgs84GeoNode(node.lat, node.lon, data_source="osm")
115119
signal = model.Signal(
116120
edge=edge,
117-
distance_edge=edge.node_a.geo_node.geo_point.get_distance_to_other_geo_point(
118-
signal_geo_point
121+
distance_edge=edge.node_a.geo_node.get_distance_to_other_geo_node(
122+
signal_geo_node
119123
),
120124
side_distance=dist_edge(node_before, node_after, node),
121125
direction=get_signal_direction(
@@ -169,7 +173,7 @@ def run(self, polygon, railway_option_types: list[str] = None):
169173
export_node = model.Node(
170174
name=node.id, turnout_side=node.tags.get("railway:turnout_side", None)
171175
)
172-
export_node.geo_node = model.Wgs84GeoNode(lat, lon).to_dbref()
176+
export_node.geo_node = model.Wgs84GeoNode(lat, lon, data_source="osm")
173177
self.topology.add_node(export_node)
174178

175179
# DFS-Like to create top and geo edges
@@ -248,7 +252,7 @@ def run(self, polygon, railway_option_types: list[str] = None):
248252
substitute_found = True
249253
new_node = model.Node()
250254
new_node.geo_node = Wgs84GeoNode(
251-
candidate.lat, candidate.lon
255+
candidate.lat, candidate.lon, data_source="osm"
252256
).to_dbref()
253257
new_edge = Edge(node, new_node)
254258
new_edge.maximum_speed = 160

orm_importer/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,23 @@ def is_end_node(node, graph):
3434
if graph.degree(node.id) == 1 or graph.degree(node.id) == 0:
3535
return True
3636

37-
if is_signal(node):
37+
if is_signal(node, graph):
3838
return False
3939

4040

41-
def is_signal(node):
41+
def is_signal(node, graph):
42+
# Exclude signals that also function as end nodes
43+
if graph.degree(node.id) == 1 or graph.degree(node.id) == 0:
44+
return False
45+
4246
# we cannot use railway=signal as a condition, as buffer stops violate this assumption.
4347
# Instead, we check for the signal direction as we cannot create a
4448
# signal without a direction anyway
4549
return "railway:signal:direction" in node.tags.keys()
4650

4751

4852
def is_switch(node, graph):
49-
return is_x(node, "switch") and graph.degree(node.id) == 3
53+
return graph.degree(node.id) == 3 # is_x(node, "switch") and
5054

5155

5256
def is_x(node, x: str):

0 commit comments

Comments
 (0)