Skip to content
Merged
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
22 changes: 13 additions & 9 deletions orm_importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from yaramo import model
from yaramo.edge import Edge
from yaramo.geo_node import Wgs84GeoNode
from yaramo.geo_point import Wgs84GeoPoint
from yaramo.topology import Topology

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

next_edge = distinct_edges[0]
Expand All @@ -102,20 +104,22 @@ def _get_next_top_node(self, node, edge: "tuple[str, str]", path):
def _add_geo_nodes(self, path, top_edge: Edge):
for idx, node_id in enumerate(path):
node = self.node_data[node_id]
if idx == 0 or is_signal(node):
if idx == 0 or is_signal(node, self.graph):
continue
top_edge.intermediate_geo_nodes.append(Wgs84GeoNode(node.lat, node.lon).to_dbref())
top_edge.intermediate_geo_nodes.append(
Wgs84GeoNode(node.lat, node.lon, data_source="osm")
)

def _add_signals(self, path, edge: model.Edge, node_before, node_after):
# append node and next_tope_node to path as they could also be signals (e.g. buffer stop)
for node_id in [int(edge.node_a.name), *path, int(edge.node_b.name)]:
node = self.node_data[node_id]
if is_signal(node):
signal_geo_point = Wgs84GeoPoint(node.lat, node.lon).to_dbref()
if is_signal(node, self.graph):
signal_geo_node = Wgs84GeoNode(node.lat, node.lon, data_source="osm")
signal = model.Signal(
edge=edge,
distance_edge=edge.node_a.geo_node.geo_point.get_distance_to_other_geo_point(
signal_geo_point
distance_edge=edge.node_a.geo_node.get_distance_to_other_geo_node(
signal_geo_node
),
side_distance=dist_edge(node_before, node_after, node),
direction=get_signal_direction(
Expand Down Expand Up @@ -169,7 +173,7 @@ def run(self, polygon, railway_option_types: list[str] = None):
export_node = model.Node(
name=node.id, turnout_side=node.tags.get("railway:turnout_side", None)
)
export_node.geo_node = model.Wgs84GeoNode(lat, lon).to_dbref()
export_node.geo_node = model.Wgs84GeoNode(lat, lon, data_source="osm")
self.topology.add_node(export_node)

# DFS-Like to create top and geo edges
Expand Down Expand Up @@ -248,7 +252,7 @@ def run(self, polygon, railway_option_types: list[str] = None):
substitute_found = True
new_node = model.Node()
new_node.geo_node = Wgs84GeoNode(
candidate.lat, candidate.lon
candidate.lat, candidate.lon, data_source="osm"
).to_dbref()
new_edge = Edge(node, new_node)
new_edge.maximum_speed = 160
Expand Down
10 changes: 7 additions & 3 deletions orm_importer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ def is_end_node(node, graph):
if graph.degree(node.id) == 1 or graph.degree(node.id) == 0:
return True

if is_signal(node):
if is_signal(node, graph):
return False


def is_signal(node):
def is_signal(node, graph):
# Exclude signals that also function as end nodes
if graph.degree(node.id) == 1 or graph.degree(node.id) == 0:
return False

# we cannot use railway=signal as a condition, as buffer stops violate this assumption.
# Instead, we check for the signal direction as we cannot create a
# signal without a direction anyway
return "railway:signal:direction" in node.tags.keys()


def is_switch(node, graph):
return is_x(node, "switch") and graph.degree(node.id) == 3
return graph.degree(node.id) == 3 # is_x(node, "switch") and


def is_x(node, x: str):
Expand Down
Loading
Loading