1
1
import folium
2
2
import streamlit as st
3
- from osmnx import distance , geocoder , graph_from_bbox , routing , features_from_bbox
3
+ from osmnx import distance , features_from_bbox , geocoder , graph_from_bbox , routing
4
4
from streamlit_folium import st_folium
5
5
6
6
bounding_box = {'min_lat' : 49.174522 , 'max_lat' : 50.526524 , 'min_lon' : 19.076385 , 'max_lon' : 21.432953 }
7
7
8
8
9
- def get_route_points (start , end ):
10
- G = graph_from_bbox (
9
+ @st .cache_resource
10
+ def get_graph ():
11
+ return graph_from_bbox (
11
12
bbox = (bounding_box ['max_lat' ], bounding_box ['min_lat' ], bounding_box ['min_lon' ], bounding_box ['max_lon' ]),
12
13
network_type = 'bike' ,
13
14
simplify = False ,
15
+ retain_all = True ,
14
16
)
17
+
18
+
19
+ @st .cache_data
20
+ def get_route_points (start , end ):
21
+ G = get_graph ()
15
22
orig = geocoder .geocode (start )
16
23
dest = geocoder .geocode (end )
17
24
o , _ = distance .nearest_nodes (G , orig [1 ], orig [0 ], return_dist = True )
@@ -28,24 +35,34 @@ def plot_route(map_, route_pts):
28
35
return map
29
36
30
37
38
+ @st .cache_data
39
+ def get_localities ():
40
+ print ('Fetching localities' )
41
+ x = tuple (
42
+ features_from_bbox (
43
+ bbox = (bounding_box ['max_lat' ], bounding_box ['min_lat' ], bounding_box ['min_lon' ], bounding_box ['max_lon' ]),
44
+ tags = {'place' : ['town' , 'vilage' ]},
45
+ )['name' ].values
46
+ )
47
+ print ('Fetched localities' )
48
+ return x
49
+
50
+
31
51
def run_server ():
32
52
st .title ('Rowerem przez Małopolskę' )
33
53
34
- localities = tuple (features_from_bbox (
35
- bbox = (bounding_box ['max_lat' ], bounding_box ['min_lat' ], bounding_box ['min_lon' ], bounding_box ['max_lon' ]),
36
- tags = {"place" : ["town" , "vilage" ]})['name' ].values
37
- )
54
+ localities = get_localities ()
38
55
39
56
cont1 = st .container ()
40
57
41
58
with cont1 :
42
59
col1 , col2 = st .columns (2 )
43
60
44
61
with col1 :
45
- origin = st .selectbox (" Skąd" , localities )
62
+ origin = st .selectbox (' Skąd' , localities )
46
63
47
64
with col2 :
48
- destination = st .selectbox (" Dokąd" , localities )
65
+ destination = st .selectbox (' Dokąd' , localities )
49
66
50
67
cont2 = st .container ()
51
68
0 commit comments