Skip to content

Commit 03ffc6c

Browse files
Merge pull request #2 from Czaki/generate_path
Add function to calculate path
2 parents b411528 + c780ce9 commit 03ffc6c

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ repos:
33
rev: v0.6.4
44
hooks:
55
- id: ruff-format
6-
exclude: examples
76
- id: ruff
7+
args: [--show-fixes]
88
- repo: https://github.com/python-jsonschema/check-jsonschema
99
rev: 0.29.2
1010
hooks:

hackyeah2024/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import click
22

3-
from hackyeah2024.server import run_server
4-
53

64
@click.group()
75
def main():

hackyeah2024/server.py

+32-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
import folium
22
import streamlit as st
3-
3+
from osmnx import distance, geocoder, graph_from_bbox, routing
44
from streamlit_folium import st_folium
55

6+
bounding_box = {'min_lat': 49.174522, 'max_lat': 50.526524, 'min_lon': 19.076385, 'max_lon': 21.432953}
7+
68

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)
1028
return map
1129

1230

@@ -19,14 +37,14 @@ def run_server():
1937
col1, col2 = st.columns(2)
2038

2139
with col1:
22-
st.text_input("Skąd")
40+
st.text_input('Skąd')
2341

2442
with col2:
25-
st.text_input("Dokąd")
43+
st.text_input('Dokąd')
2644

2745
cont2 = st.container()
2846

29-
map_bound_coordinates=[
47+
map_bound_coordinates = [
3048
(50.526524, 19.076385),
3149
(50.526524, 21.432953),
3250
(49.174522, 21.432953),
@@ -35,26 +53,26 @@ def run_server():
3553
]
3654

3755
# center on Liberty Bell, add marker
38-
map = folium.Map(
56+
map_ = folium.Map(
3957
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)],
4159
zoom_start=9,
4260
tiles='OpenStreetMap',
4361
min_lon=19.076385,
4462
max_lon=21.432953,
4563
min_lat=49.174522,
46-
max_lat=50.526524
64+
max_lat=50.526524,
4765
)
4866
marker = folium.Marker([50.049683, 19.944544], popup='Kraków', tooltip='Kraków')
49-
map.add_child(marker)
67+
map_.add_child(marker)
5068

51-
map_bounds=folium.PolyLine(locations=map_bound_coordinates, weight=5)
69+
map_bounds = folium.PolyLine(locations=map_bound_coordinates, weight=5)
5270

53-
map.add_child(map_bounds)
71+
map_.add_child(map_bounds)
5472

5573
with cont2:
5674
# call to render Folium map in Streamlit
57-
st_data = st_folium(map, width=725)
75+
_st_data = st_folium(map_, width=725)
5876

5977

6078
if __name__ == '__main__':

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ dependencies = [
99
"streamlit",
1010
"streamlit_folium",
1111
"taxicab",
12+
"osmnx",
13+
"scikt-learn",
1214
]
1315

1416

0 commit comments

Comments
 (0)