Calculate graph edge speeds and travel times.
# 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__
'1.1.2'
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))
# KeyError: 'all edges must have `length` and `speed_kph` attributes.'
# 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
)
# Add edge travel time (seconds) to graph as new travel_time edge attributes.
G = ox.speed.add_edge_travel_times(G, precision=1)
# 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()
osmid | oneway | highway | length | geometry | speed_kph | travel_time | 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 | 4.3 | 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 | 1.3 | 퇴계로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 | 7.5 | 충무로 | 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 | 5.6 | 퇴계로 | 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 | 3.4 | 서소문로 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |