1
1
import folium
2
2
import streamlit as st
3
-
3
+ from osmnx import distance , geocoder , graph_from_bbox , routing
4
4
from streamlit_folium import st_folium
5
5
6
+ bounding_box = {'min_lat' : 49.174522 , 'max_lat' : 50.526524 , 'min_lon' : 19.076385 , 'max_lon' : 21.432953 }
7
+
6
8
7
- def plot_route (map , route_pts ):
8
- route = folium .PolyLine (locations = route_pts , weight = 2 )
9
- map .add_child (route )
9
+ def get_route_points (start , end ):
10
+ G = graph_from_bbox (
11
+ bbox = (bounding_box ['max_lat' ], bounding_box ['min_lat' ], bounding_box ['min_lon' ], bounding_box ['max_lon' ]),
12
+ network_type = 'bike' ,
13
+ simplify = False ,
14
+ )
15
+ orig = geocoder .geocode (start )
16
+ dest = geocoder .geocode (end )
17
+ o , _ = distance .nearest_nodes (G , orig [1 ], orig [0 ], return_dist = True )
18
+ d , _ = distance .nearest_nodes (G , dest [1 ], dest [0 ], return_dist = True )
19
+ # print(o, d)
20
+ route = routing .shortest_path (G , o , d )
21
+ points = [G .nodes [x ] for x in route ]
22
+ return [(x ['y' ], x ['x' ]) for x in points ]
23
+
24
+
25
+ def plot_route (map_ , route_pts ):
26
+ route = folium .PolyLine (locations = route_pts , weight = 2 )
27
+ map_ .add_child (route )
10
28
return map
11
29
12
30
@@ -19,14 +37,14 @@ def run_server():
19
37
col1 , col2 = st .columns (2 )
20
38
21
39
with col1 :
22
- st .text_input (" Skąd" )
40
+ st .text_input (' Skąd' )
23
41
24
42
with col2 :
25
- st .text_input (" Dokąd" )
43
+ st .text_input (' Dokąd' )
26
44
27
45
cont2 = st .container ()
28
46
29
- map_bound_coordinates = [
47
+ map_bound_coordinates = [
30
48
(50.526524 , 19.076385 ),
31
49
(50.526524 , 21.432953 ),
32
50
(49.174522 , 21.432953 ),
@@ -35,26 +53,26 @@ def run_server():
35
53
]
36
54
37
55
# center on Liberty Bell, add marker
38
- map = folium .Map (
56
+ map_ = folium .Map (
39
57
max_bounds = True ,
40
- location = [0.5 * (49.174522 + 50.526524 ), 0.5 * (19.944544 + 21.432953 )],
58
+ location = [0.5 * (49.174522 + 50.526524 ), 0.5 * (19.944544 + 21.432953 )],
41
59
zoom_start = 9 ,
42
60
tiles = 'OpenStreetMap' ,
43
61
min_lon = 19.076385 ,
44
62
max_lon = 21.432953 ,
45
63
min_lat = 49.174522 ,
46
- max_lat = 50.526524
64
+ max_lat = 50.526524 ,
47
65
)
48
66
marker = folium .Marker ([50.049683 , 19.944544 ], popup = 'Kraków' , tooltip = 'Kraków' )
49
- map .add_child (marker )
67
+ map_ .add_child (marker )
50
68
51
- map_bounds = folium .PolyLine (locations = map_bound_coordinates , weight = 5 )
69
+ map_bounds = folium .PolyLine (locations = map_bound_coordinates , weight = 5 )
52
70
53
- map .add_child (map_bounds )
71
+ map_ .add_child (map_bounds )
54
72
55
73
with cont2 :
56
74
# call to render Folium map in Streamlit
57
- st_data = st_folium (map , width = 725 )
75
+ _st_data = st_folium (map_ , width = 725 )
58
76
59
77
60
78
if __name__ == '__main__' :
0 commit comments