OSMWayLoader¶
In [1]:
Copied!
import geopandas as gpd
import shapely.geometry as shpg
from srai.loaders import OSMNetworkType, OSMWayLoader
from srai.constants import WGS84_CRS, REGIONS_INDEX
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.loaders import OSMNetworkType, OSMWayLoader
from srai.constants import WGS84_CRS, REGIONS_INDEX
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")
/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/srai/loaders/osm_way_loader/osm_way_loader.py:219: UserWarning: The clean_periphery argument has been deprecated and will be removed in a future release. Future behavior will be as though clean_periphery=True. G_directed = ox.graph_from_polygon( /opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/srai/loaders/osm_way_loader/osm_way_loader.py:219: UserWarning: The clean_periphery argument has been deprecated and will be removed in a future release. Future behavior will be as though clean_periphery=True. G_directed = ox.graph_from_polygon(
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)
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)
/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/srai/loaders/osm_way_loader/osm_way_loader.py:219: UserWarning: The clean_periphery argument has been deprecated and will be removed in a future release. Future behavior will be as though clean_periphery=True. G_directed = ox.graph_from_polygon(
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) |
... | ... | ... | ... | ... | ... | ... |
11423145699 | 51.152179 | 16.856252 | 3 | NaN | NaN | POINT (16.85625 51.15218) |
11423857006 | 51.103429 | 17.083927 | 1 | NaN | NaN | POINT (17.08393 51.10343) |
11443281228 | 51.135667 | 17.025515 | 3 | NaN | NaN | POINT (17.02552 51.13567) |
11443281232 | 51.135316 | 17.025949 | 1 | NaN | NaN | POINT (17.02595 51.13532) |
11445118506 | 51.087995 | 17.069919 | 3 | NaN | NaN | POINT (17.06992 51.08799) |
7380 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) |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
10129 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (16.92161 51.13979, 16.92607 51.139... |
10130 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (16.88947 51.14807, 16.88998 51.14801) |
10131 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.13358 51.15630, 17.13285 51.15582) |
10132 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (16.85625 51.15218, 16.85632 51.152... |
10133 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.02595 51.13532, 17.02586 51.135... |
10134 rows × 219 columns