OSMWayLoader¶
In [1]:
Copied!
import geopandas as gpd
import shapely.geometry as shpg
from srai.constants import REGIONS_INDEX, WGS84_CRS
from srai.loaders import OSMNetworkType, OSMWayLoader
from srai.plotting.folium_wrapper import plot_regions
from srai.regionalizers import geocode_to_region_gdf
import geopandas as gpd
import shapely.geometry as shpg
from srai.constants import REGIONS_INDEX, WGS84_CRS
from srai.loaders import OSMNetworkType, OSMWayLoader
from srai.plotting.folium_wrapper import plot_regions
from srai.regionalizers import geocode_to_region_gdf
Small area¶
In [2]:
Copied!
polygon1 = shpg.Polygon(
[
(17.1005309, 51.1100158),
(17.1020436, 51.1100427),
(17.1021938, 51.1082509),
(17.1006274, 51.1081027),
(17.1005201, 51.1099956),
]
)
polygon2 = shpg.Polygon(
[
(17.0994473, 51.1084126),
(17.1023226, 51.1086551),
(17.1023333, 51.1076312),
(17.0994473, 51.1083722),
]
)
gdf_place = gpd.GeoDataFrame(
{"geometry": [polygon1, polygon2]},
crs=WGS84_CRS,
index=gpd.pd.Index(name=REGIONS_INDEX, data=[1, 2]),
)
plot_regions(gdf_place)
polygon1 = shpg.Polygon(
[
(17.1005309, 51.1100158),
(17.1020436, 51.1100427),
(17.1021938, 51.1082509),
(17.1006274, 51.1081027),
(17.1005201, 51.1099956),
]
)
polygon2 = shpg.Polygon(
[
(17.0994473, 51.1084126),
(17.1023226, 51.1086551),
(17.1023333, 51.1076312),
(17.0994473, 51.1083722),
]
)
gdf_place = gpd.GeoDataFrame(
{"geometry": [polygon1, polygon2]},
crs=WGS84_CRS,
index=gpd.pd.Index(name=REGIONS_INDEX, data=[1, 2]),
)
plot_regions(gdf_place)
Out[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [3]:
Copied!
osmwl = OSMWayLoader(OSMNetworkType.BIKE, metadata=True)
gdf_nodes, gdf_edges = osmwl.load(gdf_place)
folium_map = plot_regions(gdf_place, colormap=["lightgray"], tiles_style="CartoDB positron")
gdf_edges.explore(m=folium_map)
gdf_nodes.explore(m=folium_map, color="orangered")
osmwl = OSMWayLoader(OSMNetworkType.BIKE, metadata=True)
gdf_nodes, gdf_edges = osmwl.load(gdf_place)
folium_map = plot_regions(gdf_place, colormap=["lightgray"], tiles_style="CartoDB positron")
gdf_edges.explore(m=folium_map)
gdf_nodes.explore(m=folium_map, color="orangered")
/root/development/srai/srai/loaders/osm_way_loader/osm_way_loader.py:229: FutureWarning: The clean_periphery argument has been deprecated and will be removed in the v2.0.0 release. Future behavior will be as though clean_periphery=True. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 G_directed = ox.graph_from_polygon( /root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:350: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 overpass_settings = _make_overpass_settings()
/root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:360: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 yield _overpass_request(data={"data": query_str}) /root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:442: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 this_pause = _get_overpass_pause(overpass_endpoint)
/root/development/srai/srai/loaders/osm_way_loader/osm_way_loader.py:237: FutureWarning: The `get_undirected` function is deprecated and will be removed in the v2.0.0 release. Replace it with `convert.to_undirected` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 G_undirected = ox.utils_graph.get_undirected(G_directed) /root/development/srai/srai/loaders/osm_way_loader/osm_way_loader.py:229: FutureWarning: The clean_periphery argument has been deprecated and will be removed in the v2.0.0 release. Future behavior will be as though clean_periphery=True. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 G_directed = ox.graph_from_polygon( /root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:350: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 overpass_settings = _make_overpass_settings()
/root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:360: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 yield _overpass_request(data={"data": query_str}) /root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:442: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 this_pause = _get_overpass_pause(overpass_endpoint)
/root/development/srai/srai/loaders/osm_way_loader/osm_way_loader.py:237: FutureWarning: The `get_undirected` function is deprecated and will be removed in the v2.0.0 release. Replace it with `convert.to_undirected` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 G_undirected = ox.utils_graph.get_undirected(G_directed)
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
Copied!
gdf_nodes
gdf_nodes
Out[4]:
y | x | street_count | geometry | |
---|---|---|---|---|
osmid | ||||
243060098 | 51.109982 | 17.102308 | 3 | POINT (17.10231 51.10998) |
243060099 | 51.109840 | 17.101177 | 4 | POINT (17.10118 51.10984) |
243060100 | 51.108360 | 17.101659 | 4 | POINT (17.10166 51.10836) |
248215261 | 51.108587 | 17.103112 | 3 | POINT (17.10311 51.10859) |
309274874 | 51.108156 | 17.099991 | 4 | POINT (17.09999 51.10816) |
309274902 | 51.109626 | 17.099521 | 3 | POINT (17.09952 51.10963) |
2997376256 | 51.106468 | 17.102136 | 4 | POINT (17.10214 51.10647) |
3078968718 | 51.109302 | 17.102673 | 3 | POINT (17.10267 51.10930) |
3078968723 | 51.109338 | 17.101337 | 3 | POINT (17.10134 51.10934) |
3078968727 | 51.109399 | 17.101823 | 3 | POINT (17.10182 51.10940) |
3773384244 | 51.109898 | 17.101164 | 1 | POINT (17.10116 51.10990) |
4962348415 | 51.109878 | 17.101000 | 1 | POINT (17.10100 51.10988) |
5047464797 | 51.109344 | 17.101335 | 3 | POINT (17.10133 51.10934) |
5047464798 | 51.109279 | 17.100829 | 3 | POINT (17.10083 51.10928) |
5047464799 | 51.109214 | 17.100853 | 1 | POINT (17.10085 51.10921) |
5047464814 | 51.109132 | 17.099674 | 3 | POINT (17.09967 51.10913) |
5970627769 | 51.108450 | 17.102133 | 1 | POINT (17.10213 51.10845) |
11101777577 | 51.110161 | 17.100174 | 4 | POINT (17.10017 51.11016) |
5047464931 | 51.108343 | 17.099931 | 3 | POINT (17.09993 51.10834) |
5047464932 | 51.108306 | 17.099657 | 1 | POINT (17.09966 51.10831) |
In [5]:
Copied!
gdf_edges
gdf_edges
Out[5]:
from | to | key | osmid | name | reversed | length | ref | oneway | lanes-1 | ... | bicycle-official | lit-yes | lit-no | lit-sunset-sunrise | lit-24/7 | lit-automatic | lit-disused | lit-limited | lit-interval | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
feature_id | |||||||||||||||||||||
0 | 243060099 | 243060098 | 0 | 22661452 | Partyzantów | False | 80.550 | NaN | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10118 51.10984, 17.10128 51.109... |
1 | 5047464797 | 243060099 | 0 | 22661453 | Andrzeja Potebni | True | 56.235 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10133 51.10934, 17.10133 51.109... |
2 | 3773384244 | 243060099 | 0 | 517177952 | NaN | False | 6.466 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10116 51.10990, 17.10117 51.109... |
3 | 309274902 | 243060099 | 0 | 22661452 | Partyzantów | False | 118.021 | NaN | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09952 51.10963, 17.09961 51.109... |
4 | 2997376256 | 243060100 | 0 | [22661453, 511013133] | Andrzeja Potebni | True | 213.556 | NaN | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10214 51.10647, 17.10213 51.106... |
5 | 3078968723 | 243060100 | 0 | 22661453 | Andrzeja Potebni | False | 111.075 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10134 51.10934, 17.10134 51.109... |
6 | 248215261 | 243060100 | 0 | 22661454 | Pierwszej Dywizji | True | 104.645 | NaN | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10311 51.10859, 17.10304 51.108... |
7 | 309274874 | 243060100 | 0 | 28157157 | Pierwszej Dywizji | True | 118.621 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09999 51.10816, 17.10002 51.108... |
8 | 3078968727 | 3078968718 | 0 | 303524708 | NaN | True | 68.723 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10182 51.10940, 17.10208 51.109... |
9 | 5047464797 | 3078968723 | 0 | 22661453 | Andrzeja Potebni | False | 0.713 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10133 51.10934, 17.10134 51.10934) |
10 | 3078968727 | 3078968723 | 0 | 303524709 | NaN | True | 34.610 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10182 51.10940, 17.10163 51.109... |
11 | 5970627769 | 3078968727 | 0 | 632330247 | NaN | False | 107.725 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10213 51.10845, 17.10207 51.108... |
12 | 11101777577 | 4962348415 | 0 | 506514653 | NaN | False | 67.514 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10017 51.11016, 17.10031 51.110... |
13 | 5047464798 | 5047464797 | 0 | 517177960 | NaN | False | 36.077 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10083 51.10928, 17.10105 51.109... |
14 | 5047464799 | 5047464798 | 0 | 517177961 | NaN | True | 7.428 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10085 51.10921, 17.10083 51.109... |
15 | 5047464814 | 5047464798 | 0 | 517177961 | NaN | False | 139.423 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09967 51.10913, 17.09970 51.109... |
16 | 5047464931 | 309274874 | 0 | 28157154 | Pułkownika Franciszka Nulla | True | 21.185 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09993 51.10834, 17.09994 51.108... |
17 | 5047464931 | 5047464814 | 0 | 28157154 | Pułkownika Franciszka Nulla | False | 89.632 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09993 51.10834, 17.09992 51.108... |
18 | 5047464932 | 5047464931 | 0 | 517177966 | NaN | True | 19.530 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09966 51.10831, 17.09989 51.108... |
19 rows × 227 columns
Bigger area¶
In [6]:
Copied!
gdf_place = geocode_to_region_gdf("Wroclaw, Poland")
plot_regions(gdf_place)
gdf_place = geocode_to_region_gdf("Wroclaw, Poland")
plot_regions(gdf_place)
/root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_nominatim.py:65: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 return _nominatim_request(params=params, request_type=request_type)
Out[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [7]:
Copied!
osmwl = OSMWayLoader(OSMNetworkType.DRIVE)
gdf_nodes, gdf_edges = osmwl.load(gdf_place)
osmwl = OSMWayLoader(OSMNetworkType.DRIVE)
gdf_nodes, gdf_edges = osmwl.load(gdf_place)
/root/development/srai/srai/loaders/osm_way_loader/osm_way_loader.py:229: FutureWarning: The clean_periphery argument has been deprecated and will be removed in the v2.0.0 release. Future behavior will be as though clean_periphery=True. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 G_directed = ox.graph_from_polygon( /root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:350: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 overpass_settings = _make_overpass_settings()
/root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:360: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 yield _overpass_request(data={"data": query_str}) /root/development/srai/.venv/lib/python3.10/site-packages/osmnx/_overpass.py:442: FutureWarning: `settings.timeout` is deprecated and will be removed in the v2.0.0 release: use `settings.requests_timeout` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 this_pause = _get_overpass_pause(overpass_endpoint)
/root/development/srai/srai/loaders/osm_way_loader/osm_way_loader.py:237: FutureWarning: The `get_undirected` function is deprecated and will be removed in the v2.0.0 release. Replace it with `convert.to_undirected` instead. See the OSMnx v2 migration guide: https://github.com/gboeing/osmnx/issues/1123 G_undirected = ox.utils_graph.get_undirected(G_directed)
In [8]:
Copied!
ax = gdf_place.plot(color="white", edgecolor="black", figsize=(16, 16))
gdf_edges.plot(ax=ax)
gdf_nodes.plot(ax=ax, marker="o", color="orangered", markersize=2, zorder=2)
ax = gdf_place.plot(color="white", edgecolor="black", figsize=(16, 16))
gdf_edges.plot(ax=ax)
gdf_nodes.plot(ax=ax, marker="o", color="orangered", markersize=2, zorder=2)
Out[8]:
<Axes: >
In [9]:
Copied!
gdf_nodes
gdf_nodes
Out[9]:
y | x | street_count | highway | ref | geometry | |
---|---|---|---|---|---|---|
osmid | ||||||
95584835 | 51.083111 | 17.049513 | 4 | NaN | NaN | POINT (17.04951 51.08311) |
95584841 | 51.084699 | 17.064367 | 3 | NaN | NaN | POINT (17.06437 51.08470) |
95584850 | 51.083328 | 17.035057 | 4 | NaN | NaN | POINT (17.03506 51.08333) |
95584852 | 51.083009 | 17.053573 | 4 | NaN | NaN | POINT (17.05357 51.08301) |
95584855 | 51.083333 | 17.034685 | 4 | NaN | NaN | POINT (17.03468 51.08333) |
... | ... | ... | ... | ... | ... | ... |
12179148203 | 51.147960 | 16.950242 | 1 | NaN | NaN | POINT (16.95024 51.14796) |
12179149003 | 51.146505 | 16.949783 | 1 | NaN | NaN | POINT (16.94978 51.14650) |
12179149102 | 51.147324 | 16.950096 | 1 | NaN | NaN | POINT (16.95010 51.14732) |
12181655737 | 51.113458 | 17.091037 | 3 | NaN | NaN | POINT (17.09104 51.11346) |
12181655738 | 51.113406 | 17.090639 | 4 | NaN | NaN | POINT (17.09064 51.11341) |
7510 rows × 6 columns
In [10]:
Copied!
gdf_edges
gdf_edges
Out[10]:
oneway | lanes-1 | lanes-2 | lanes-3 | lanes-4 | lanes-5 | lanes-6 | lanes-7 | lanes-8 | lanes-9 | ... | bicycle-official | lit-yes | lit-no | lit-sunset-sunrise | lit-24/7 | lit-automatic | lit-disused | lit-limited | lit-interval | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
feature_id | |||||||||||||||||||||
0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.04951 51.08311, 17.04947 51.083... |
1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.04951 51.08311, 17.04933 51.083... |
2 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.05357 51.08301, 17.05335 51.082... |
3 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.04960 51.08289, 17.04955 51.083... |
4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.06450 51.08460, 17.06437 51.08470) |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
10289 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.08678 51.04984, 17.08677 51.049... |
10290 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (16.98736 51.07589, 16.98748 51.07592) |
10291 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.08686 51.10119, 17.08667 51.10103) |
10292 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (16.95010 51.14732, 16.95027 51.147... |
10293 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09104 51.11346, 17.09096 51.113... |
10294 rows × 219 columns