OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

oneway:bicycle=no in OSMNX graph with network_type='bike'

  • Thread starter Thread starter FesterShinetop
  • Start date Start date
F

FesterShinetop

Guest
I am working on an asssessment of bicycle infrastructure along common routes within european cities. In the process I encountered the following problem:

Within Europe it is quite common to allow cyclists to pass oneway streets in both directions (I don't know if that is a thing in North America). The correspondent edges in OSM are tagged with oneway=yes and oneway:bicycle=no.

Using the osmnx.k_shortest_paths function in a graph with network_type='bike', I found out that riding along oneway streets in the opposite direction is avoided, even though it is legal.

This is the code I used for testing. For motorized transport, the Marienstraße in its northern section is only allowed to be used heading north. For bicycles it is free in both directions. Nevertheless the routing function makes a detour when going southwards. In the other (generally allowed) direction the street is used. I included a test, whether the edges are tagged correctly (which they are).

Code:
import osmnx as ox


add_tags = (['oneway:bicycle'])
ox.settings.useful_tags_way = ox.settings.useful_tags_way + add_tags
G = ox. graph_from_place("Karlsruhe, Germany", network_type='bike')
start = ox.nearest_nodes(G, 8.408005310258606, 49.003891115254056,  return_dist=False)  # Kommödchen
dest = ox.nearest_nodes(G, 8.408489900323096, 48.99637841654651, return_dist=False)  # Yuki Sushi
test = ox.k_shortest_paths(G, start, dest, 1, weight='length')
test_list = list(test)
test_nodes = test_list[0]
test_edges = ox.utils_graph.route_to_gdf(G, test_nodes, weight='length')
fig, ax = ox.plot_graph_route(G, test_nodes, route_color='r', route_linewidth=5, node_size=20)

test_backwards = test = ox.k_shortest_paths(G, dest, start, 1, weight='length')
back_list = list(test_backwards)
back_nodes = back_list[0]
back_edges = ox.utils_graph.route_to_gdf(G, back_nodes, weight='length')
fig_b, ax_b = ox.plot_graph_route(G, back_nodes, route_color='r', route_linewidth=5, node_size=20)

for index, row in back_edges.iterrows():
    print(row["oneway"], row["oneway:bicycle"])

Is there a workaround to reverse the respective edges according to the oneway:bicycle tags and add them to the graph?
<p>I am working on an asssessment of bicycle infrastructure along common routes within european cities. In the process I encountered the following problem:</p>
<p>Within Europe it is quite common to allow cyclists to pass oneway streets in both directions (I don't know if that is a thing in North America). The correspondent edges in OSM are tagged with <code>oneway=yes</code> and <code>oneway:bicycle=no</code>.</p>
<p>Using the <code>osmnx.k_shortest_paths</code> function in a graph with <code>network_type='bike'</code>, I found out that riding along oneway streets in the opposite direction is avoided, even though it is legal.</p>
<p>This is the code I used for testing. For motorized transport, the Marienstraße in its northern section is only allowed to be used heading north. For bicycles it is free in both directions. Nevertheless the routing function makes a detour when going southwards. In the other (generally allowed) direction the street is used. I included a test, whether the edges are tagged correctly (which they are).</p>
<pre><code>import osmnx as ox


add_tags = (['oneway:bicycle'])
ox.settings.useful_tags_way = ox.settings.useful_tags_way + add_tags
G = ox. graph_from_place("Karlsruhe, Germany", network_type='bike')
start = ox.nearest_nodes(G, 8.408005310258606, 49.003891115254056, return_dist=False) # Kommödchen
dest = ox.nearest_nodes(G, 8.408489900323096, 48.99637841654651, return_dist=False) # Yuki Sushi
test = ox.k_shortest_paths(G, start, dest, 1, weight='length')
test_list = list(test)
test_nodes = test_list[0]
test_edges = ox.utils_graph.route_to_gdf(G, test_nodes, weight='length')
fig, ax = ox.plot_graph_route(G, test_nodes, route_color='r', route_linewidth=5, node_size=20)

test_backwards = test = ox.k_shortest_paths(G, dest, start, 1, weight='length')
back_list = list(test_backwards)
back_nodes = back_list[0]
back_edges = ox.utils_graph.route_to_gdf(G, back_nodes, weight='length')
fig_b, ax_b = ox.plot_graph_route(G, back_nodes, route_color='r', route_linewidth=5, node_size=20)

for index, row in back_edges.iterrows():
print(row["oneway"], row["oneway:bicycle"])
</code></pre>
<p>Is there a workaround to reverse the respective edges according to the oneway:bicycle tags and add them to the graph?</p>
 

Latest posts

Top