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")
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.1093) |
3078968723 | 51.109338 | 17.101337 | 3 | POINT (17.10134 51.10934) |
3078968727 | 51.109399 | 17.101823 | 3 | POINT (17.10182 51.1094) |
3773384244 | 51.109898 | 17.101164 | 1 | POINT (17.10116 51.1099) |
4962348415 | 51.109878 | 17.101000 | 1 | POINT (17.101 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.550303 | 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.235522 | 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.465912 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10116 51.1099, 17.10117 51.1098... |
3 | 309274902 | 243060099 | 0 | 22661452 | Partyzantów | False | 118.021436 | 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.555307 | 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.075360 | 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.644239 | 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.619989 | 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.721857 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10182 51.1094, 17.10208 51.1094... |
9 | 5047464797 | 3078968723 | 0 | 22661453 | Andrzeja Potebni | False | 0.712976 | 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.609679 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10182 51.1094, 17.10163 51.1093... |
11 | 5970627769 | 3078968727 | 0 | 632330247 | NaN | False | 107.725650 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.10213 51.10845, 17.10208 51.108... |
12 | 11101777577 | 4962348415 | 0 | 506514653 | NaN | False | 67.514528 | 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.077196 | 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.427304 | 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.422132 | NaN | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09967 51.10913, 17.0997 51.1091... |
16 | 5047464931 | 309274874 | 0 | 28157154 | Pułkownika Franciszka Nulla | True | 21.185459 | 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.631725 | 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.530508 | 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)
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 | railway | ref | geometry | |
---|---|---|---|---|---|---|---|
osmid | |||||||
95584835 | 51.083111 | 17.049513 | 4 | NaN | NaN | NaN | POINT (17.04951 51.08311) |
95584841 | 51.084699 | 17.064367 | 3 | NaN | NaN | NaN | POINT (17.06437 51.0847) |
95584850 | 51.083328 | 17.035057 | 4 | NaN | NaN | NaN | POINT (17.03506 51.08333) |
95584852 | 51.083009 | 17.053573 | 4 | NaN | NaN | NaN | POINT (17.05357 51.08301) |
95584855 | 51.083333 | 17.034685 | 4 | NaN | NaN | NaN | POINT (17.03468 51.08333) |
... | ... | ... | ... | ... | ... | ... | ... |
12233584384 | 51.095015 | 17.013167 | 1 | NaN | NaN | NaN | POINT (17.01317 51.09501) |
12247141706 | 51.127020 | 16.965550 | 1 | NaN | NaN | NaN | POINT (16.96555 51.12702) |
12247141708 | 51.126842 | 16.965416 | 1 | NaN | NaN | NaN | POINT (16.96542 51.12684) |
12264480684 | 51.089869 | 16.994548 | 1 | NaN | NaN | NaN | POINT (16.99455 51.08987) |
12265658791 | 51.075867 | 16.986205 | 1 | NaN | NaN | NaN | POINT (16.98621 51.07587) |
7561 rows × 7 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.0496 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.0645 51.0846, 17.06437 51.0847) |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
10347 | 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.98744 51.075... |
10348 | 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) |
10349 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (16.9501 51.14732, 16.95027 51.1479... |
10350 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (17.09113 51.11347, 17.091 51.11347... |
10351 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LINESTRING (16.93992 51.1001, 16.94017 51.1006... |
10352 rows × 219 columns