WaysAhead Global commited on
Commit
8b97955
Β·
verified Β·
1 Parent(s): e1ba032

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +111 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,113 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ import geopandas as gpd
3
+ import pandas as pd
4
+ import pydeck as pdk
5
+ import numpy as np
6
+ import osmnx as ox
7
+ from streamlit_folium import st_folium
8
+ import folium
9
+
10
+ st.set_page_config(layout="wide")
11
+ st.title("🧠 Dubai Digital Twin – Interactive Map")
12
+
13
+ # --- Sidebar Layer Controls ---
14
+ st.sidebar.title("πŸ—ΊοΈ Layer Toggles")
15
+ show_buildings = st.sidebar.checkbox("Show Buildings", True)
16
+ show_malls = st.sidebar.checkbox("Show Malls", True)
17
+ show_footfall = st.sidebar.checkbox("Show Footfall", True)
18
+ show_parks = st.sidebar.checkbox("Show Parks", True)
19
+ show_metro_lines = st.sidebar.checkbox("Show Metro Lines", True)
20
+ show_metro_stations = st.sidebar.checkbox("Show Metro Stations", True)
21
+ show_move_sim = st.sidebar.checkbox("Simulate Entity Movement", True)
22
+
23
+ # --- Legend ---
24
+ st.sidebar.markdown("---")
25
+ st.sidebar.markdown("### πŸ“Œ Legend")
26
+ st.sidebar.markdown("- πŸ—οΈ Buildings: Gray")
27
+ st.sidebar.markdown("- πŸ›οΈ Malls: Blue / Green / Orange")
28
+ st.sidebar.markdown("- 🌳 Parks: Green")
29
+ st.sidebar.markdown("- πŸ“Š Footfall: Red")
30
+ st.sidebar.markdown("- πŸš‡ Metro Lines: Blue Line")
31
+ st.sidebar.markdown("- πŸš‰ Metro Stations: Yellow Dot")
32
+
33
+ # --- Load Dubai Boundary ---
34
+ st.subheader("🌍 Getting Dubai boundary...")
35
+ try:
36
+ dubai = ox.geocode_to_gdf("Dubai, United Arab Emirates")
37
+ dubai_polygon = dubai.geometry.values[0]
38
+ bounds = dubai_polygon.bounds
39
+ west, south, east, north = bounds[0], bounds[1], bounds[2], bounds[3]
40
+ bbox = (west, south, east, north)
41
+ st.success("βœ… Dubai boundary fetched.")
42
+ except Exception as e:
43
+ st.error(f"❌ Boundary fetch failed: {e}")
44
+ st.stop()
45
+
46
+ # --- Real Data Sources ---
47
+ try:
48
+ malls = ox.features_from_bbox(bbox, tags={"shop": "mall"})
49
+ malls_points = malls[malls.geometry.type == "Point"]
50
+
51
+ parks = ox.features_from_bbox(bbox, tags={"leisure": "park"})
52
+ parks_points = parks[parks.geometry.type == "Point"]
53
+
54
+ metro_stations = ox.features_from_bbox(bbox, tags={"railway": "station"})
55
+ metro_station_points = metro_stations[metro_stations.geometry.type == "Point"]
56
+
57
+ footfall = pd.read_excel("data/jj_with_footfall.xlsx")
58
+ except Exception as e:
59
+ st.warning(f"⚠️ OSM or data file fetch failed: {e}")
60
+
61
+ # --- Movement Simulation Map ---
62
+ if show_move_sim:
63
+ st.subheader("🎯 Simulate Object Movement")
64
+ fmap = folium.Map(location=[25.2048, 55.2708], zoom_start=12)
65
+
66
+ # Malls
67
+ for _, row in malls_points.iterrows():
68
+ folium.Marker(
69
+ location=[row.geometry.y, row.geometry.x],
70
+ popup=f"Mall: {row.get('name', 'Unnamed')} (Drag me)",
71
+ tooltip=row.get('name', 'Mall'),
72
+ draggable=True,
73
+ icon=folium.Icon(color="blue", icon="shopping-cart", prefix="fa")
74
+ ).add_to(fmap)
75
+
76
+ # Parks
77
+ for _, row in parks_points.iterrows():
78
+ folium.Marker(
79
+ location=[row.geometry.y, row.geometry.x],
80
+ popup=f"Park: {row.get('name', 'Unnamed')} (Drag me)",
81
+ tooltip=row.get('name', 'Park'),
82
+ draggable=True,
83
+ icon=folium.Icon(color="green", icon="tree", prefix="fa")
84
+ ).add_to(fmap)
85
+
86
+ # Metro Stations
87
+ for _, row in metro_station_points.iterrows():
88
+ folium.Marker(
89
+ location=[row.geometry.y, row.geometry.x],
90
+ popup=f"Metro Station: {row.get('name', 'Unnamed')} (Drag me)",
91
+ tooltip=row.get('name', 'Metro'),
92
+ draggable=True,
93
+ icon=folium.Icon(color="orange", icon="train", prefix="fa")
94
+ ).add_to(fmap)
95
+
96
+ # Footfall points
97
+ if show_footfall:
98
+ for _, row in footfall.dropna(subset=["latitude", "longitude"]).iterrows():
99
+ folium.CircleMarker(
100
+ location=[row["latitude"], row["longitude"]],
101
+ radius=4,
102
+ color="red",
103
+ fill=True,
104
+ fill_opacity=0.6,
105
+ tooltip="Footfall"
106
+ ).add_to(fmap)
107
+
108
+ moved = st_folium(fmap, width=1000, height=600)
109
 
110
+ if moved and moved.get("last_object_clicked"):
111
+ lat = moved["last_object_clicked"]["lat"]
112
+ lon = moved["last_object_clicked"]["lng"]
113
+ st.success(f"πŸ“ New Position: {lat}, {lon}")