OsmRx example¶
Imports and prepare input parameters¶
In [1]:
from IPython.display import display
from bokeh.plotting import output_notebook
output_notebook()
In [2]:
# Set a location name
location = "Roanne"
Get POIs¶
In [3]:
%%time
from osmrx import Pois
pois_object = Pois()
pois_object.from_location(location)
# Get the roads data: a list of dict containing the geometry and the attributes
pois_data = pois_object.data
2025-01-02 14:07:20 - Pois - INFO : Building OsmFeatureModes.poi Data
2025-01-02 14:07:20 - Pois - INFO : Building the query
2025-01-02 14:07:21 - Pois - INFO : NominatimApi: Query 200:OK in 0.44 sec.
2025-01-02 14:07:21 - Pois - INFO : From Roanne
2025-01-02 14:07:21 - Pois - INFO : Building the query
2025-01-02 14:07:21 - Pois - INFO : Execute the query
2025-01-02 14:07:23 - Pois - INFO : OverpassApi: Query 200:OK in 1.47 sec.
CPU times: user 708 ms, sys: 53.1 ms, total: 761 ms Wall time: 2.62 s
Get Roads¶
In [4]:
%%time
from osmrx import Roads
# Let's to get the roads network and connect POIs found on the same location
vehicle_object = Roads("vehicle",
pois_object.data)
vehicle_object.from_location(location)
# Get the roads data: a list of dict containing the geometry and the attributes
roads_data = vehicle_object.data
2025-01-02 14:07:23 - Roads - INFO : Building OsmFeatureModes.vehicle Data
2025-01-02 14:07:23 - Roads - INFO : Building the query
2025-01-02 14:07:23 - Roads - INFO : NominatimApi: Query 200:OK in 0.19 sec.
2025-01-02 14:07:23 - Roads - INFO : From Roanne
2025-01-02 14:07:23 - Roads - INFO : Building the query
2025-01-02 14:07:23 - Roads - INFO : Execute the query
2025-01-02 14:07:25 - Roads - INFO : OverpassApi: Query 200:OK in 1.23 sec.
2025-01-02 14:07:25 - Roads - INFO : Network cleaning...
2025-01-02 14:07:25 - Roads - INFO : Starting: Adding new nodes on the network
2025-01-02 14:07:25 - Roads - INFO : Find nearest line for each node
2025-01-02 14:07:25 - Roads - INFO : Split line
2025-01-02 14:07:25 - Roads - INFO : Starting: Find intersections
2025-01-02 14:07:25 - Roads - INFO : Done: Find intersections
2025-01-02 14:07:25 - Roads - INFO : Build lines
2025-01-02 14:07:27 - Roads - INFO : Graph built
CPU times: user 1.96 s, sys: 45.4 ms, total: 2 s Wall time: 4.19 s
Display roads and nodes¶
In [5]:
%%time
from bokeh.plotting import show
import geopandas as gpd
from gdf2bokeh import Gdf2Bokeh
map_session = Gdf2Bokeh(
"My network map",
width=800,
height=600,
background_map_name="CARTODBPOSITRON"
)
map_session.add_layer_from_dict_list("Roads", roads_data, from_epsg=4326,
color="black")
map_session.add_layer_from_dict_list("POIs", pois_data, from_epsg=4326,
color="blue", size=9)
map_session.add_layers_on_maps()
show(map_session.figure)
BokehDeprecationWarning: 'circle() method with size value' was deprecated in Bokeh 3.4.0 and will be removed, use 'scatter(size=...) instead' instead.