OSMnx Bike Infrastructure duplication

31 views Asked by At

I want to use the osmnx.graph.from_bbox function to assess bicycle infrastructure. However, there are some roads that show the road itself and then the adjacent bike path.

import networkx as nx
import osmnx as ox
import math

ox.config(use_cache=True, log_console=True)
useful_tags_way = ['bus','bridge', 'tunnel', 'oneway', 'lanes','foot', 'ref', 'name',
                    'highway', 'maxspeed', 'service', 'access', 'area','landuse',
                    'width','cycle_network', 'est_width', 'junction', 'surface', 'bicycle', 'traffic_sign','oneway:bicycle'
                    'cycle_barrier', 'cycleway','cycleway:both:lane', 'cycleway:both','smoothness','parking','parking:lane:right','parking:lane:left',
                    'cycleway:right','cycleway:right:lane','junction','level','class:bicycle', 'tracktype', 
                    'cylceway:left', 'cycleway:left:lane','bicycle:conditional','oneway:bicycle','cycleway:surface', 'bicycle_road',
                    'cycleway:width','cycleway:lane','hgv','cycleway:left:segregated','cycleway:right:segregated']
ox.utils.config(useful_tags_way=useful_tags_way)

# Mittelpunkt des gewünschten Bereich8s
latitude, longitude =  48.016696, 7.810164 #Path47.985649,7.829814 #Basler47.985293,7.830120  
# Konvertieren Sie 500 Meter in Grad
# Ca. 111320 Meter pro Breitengrad
meters_per_lat = 111320  
# Ca. 40075000 * cos(latitude) Meter pro Längengrad
meters_per_lon = 40075000 * math.cos(math.radians(latitude)) / 360

# Berechnen der Halbwerte der Breite und Länge in Grad für 500m
delta_lat = 150 / meters_per_lat
delta_lon = 150 / meters_per_lon

# Berechnen der Bounding Box
north = latitude + delta_lat
south = latitude
east = longitude + delta_lon
west = longitude

bbox= (west, south, east, north)
G = ox.graph_from_bbox(north, south, east, west, network_type='bike', simplify=False, retain_all=True, truncate_by_edge=True)
# Konvertieren Sie das Netzwerk in GeoDataFrames
gdf_nodes, gdf_edges = ox.graph_to_gdfs(G)

# Überprüfen Sie die verfügbaren Spalten, um zu sehen, ob 'surface' und 'bicycle' enthalten sind
print(gdf_edges.columns)

# Speichern Sie die Kanten und Knoten als CSV
gdf_edges.to_csv('edges.csv', index=False)
gdf_nodes.to_csv('nodes.csv', index=False)

print("Die Daten wurden als edges.csv und nodes.csv gespeichert.")

G_projected = ox.project_graph(G)
ox.plot_graph(G_projected)

This results in a duplication of the assessment. Can I assign which path belongs to which highway so that they are only included individually in the assessment?

Can I assign which path belongs to which highway so that they are only included individually in the assessment?

1

There are 1 answers

0
gboeing On

However, there are some roads that show the road itself and then the adjacent bike path.

Yes that is correct: you are modeling a network that allows cycling. If OSM's road is tagged such that cycling is not forbidden on it, then it appears in your model, as does the explicit bike path. You can filter out roads if you don't want them in the model by passing a custom_filter argument: https://osmnx.readthedocs.io/en/stable/user-reference.html#osmnx.graph.graph_from_bbox

import osmnx as ox

extra_tags = ['cycleway:left', 'foot', 'bicycle:conditional', 'traffic_sign', 'cycleway:right:segregated', 'tracktype', 'cycleway:lane', 'cycle_network', 'cycleway:left:lane', 'cycleway:width', 'class:bicycle', 'oneway:bicyclecycle_barrier', 'oneway:bicycle', 'parking:lane:right', 'bicycle_road', 'parking:lane:left', 'bicycle', 'cycleway:right:lane', 'cycleway:right', 'cycleway:surface', 'surface', 'parking', 'bus', 'hgv', 'smoothness', 'cycleway:both', 'level', 'cycleway', 'cycleway:left:segregated', 'cycleway:both:lane']
ox.settings.useful_tags_way += extra_tags
ox.settings.log_console = True
bbox = ox.utils_geo.bbox_from_point((48.016696, 7.810164), dist=150)

# model a bikeable network within that bounding box
G1 = ox.graph_from_bbox(*bbox, network_type='bike', simplify=False, retain_all=True, truncate_by_edge=True)

# or model the network using your own custom Overpass filter, for example:
cf = '["highway"]["highway"!~"trunk|primary"]["area"!~"yes"]["bicycle"!~"no"]'
G2 = ox.graph_from_bbox(*bbox, network_type='bike', custom_filter=cf, simplify=False, retain_all=True, truncate_by_edge=True)
fig, ax = ox.plot_graph(ox.project_graph(G2))

Also note that you are using some very old deprecated code that is scheduled for removal in a future release of OSMnx.