forked from wybert/routing_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlite_app.py
72 lines (55 loc) · 2 KB
/
streamlite_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import streamlit as st
import pandas as pd
import numpy as np
from stqdm import stqdm
st.title('Routing Calculator')
st.write("""This app is used to calculate the distance and duration between two points. This app is developed by [Xiaokang Fu](https://gis.harvard.edu/people/xiaokang-fu) and [Devika Kakkar](https://gis.harvard.edu/people/devika-kakkar).
Please contact [Devika Kakkar](mailto:[email protected]) for any questions.""")
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
st.write(df)
st.write('Please select the columns for origin and destination longitude and latitude.')
# orignal longitude selection
col1, col2, col3, col4 = st.columns(4)
with col1:
orig_lon = st.selectbox(
'Origin Longitude',
# set default value
(df.columns),
index=4)
with col2:
orig_lat = st.selectbox(
'Origin Latitude',
(df.columns),
index=5
)
with col3:
dest_lon = st.selectbox(
'Destination Longitude',
(df.columns),
index=2)
with col4:
dest_lat = st.selectbox(
'Destination Latitude',
(df.columns),
index=3)
st.write('You selected:', orig_lon, orig_lat, dest_lon, dest_lat)
from georouting.routers import OSRMRouter
router = OSRMRouter(mode="driving")
for k,v in stqdm(df.iterrows(), total=df.shape[0]):
origin = (v[orig_lat], v[orig_lon])
destination = (v[dest_lat], v[dest_lon])
route = router.get_route(origin, destination)
df.loc[k, 'distance (m)'] = route.get_distance()
df.loc[k, 'duration (s)'] = route.get_duration()
st.balloons()
st.write('Done!')
# download df as csv
st.download_button(
label="Download data as CSV",
data=df.to_csv().encode("utf-8"),
file_name='routing.csv',
mime='text/csv'
)
st.write(df)