osmnx.speed module¶

Calculate graph edge speeds and travel times.

In [ ]:
# OSMnx: New Methods for Acquiring, Constructing, Analyzing, and Visualizing Complex Street Networks
import osmnx as ox

ox.config(use_cache=True, log_console=False)
ox.__version__
Out[ ]:
'1.1.2'
In [ ]:
query = '중구, 서울특별시, 대한민국'
network_type = 'drive' # "all_private", "all", "bike", "drive", "drive_service", "walk"

# Create graph from OSM within the boundaries of some geocodable place(s).
G = ox.graph_from_place(query, network_type=network_type)

# Plot a graph.
fig, ax = ox.plot_graph(G)
/Users/junhyun/.pyenv/versions/3.8.5/envs/openstreetmap/lib/python3.8/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
In [ ]:
# Add edge speeds (km per hour) to graph as new speed_kph edge attributes.
G = ox.speed.add_edge_speeds(
    G, 
    hwy_speeds=None, 
    fallback=None, 
    precision=1
)
In [ ]:
# Convert a MultiDiGraph to node and/or edge GeoDataFrames.
# AttributeError: 'tuple' object has no attribute 'head'
gdf = ox.graph_to_gdfs(G, nodes=False)
gdf.head()
Out[ ]:
osmid oneway highway length geometry speed_kph name lanes maxspeed junction ref bridge tunnel access
u v key
300879699 436870699 0 37399712 False unclassified 52.517 LINESTRING (127.00024 37.55161, 127.00028 37.5... 44.1 NaN NaN NaN NaN NaN NaN NaN NaN
414685366 7301027934 0 772527390 False residential 10.713 LINESTRING (126.99319 37.56110, 126.99320 37.5... 30.0 퇴계로34길 NaN NaN NaN NaN NaN NaN NaN
7206358785 0 219696192 True secondary 117.882 LINESTRING (126.99319 37.56110, 126.99317 37.5... 56.3 충무로 NaN NaN NaN NaN NaN NaN NaN
2374697789 0 219696193 True secondary 87.216 LINESTRING (126.99319 37.56110, 126.99306 37.5... 56.3 퇴계로 NaN NaN NaN NaN NaN NaN NaN
414685371 4223315309 0 333580689 True secondary 53.798 LINESTRING (126.96754 37.56142, 126.96813 37.5... 56.3 서소문로 NaN NaN NaN NaN NaN NaN NaN