Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,101 +1,112 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pydeck as pdk
|
| 3 |
-
import pandas as pd
|
| 4 |
import geopandas as gpd
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
|
| 8 |
-
# Load GeoJSON data function
|
| 9 |
@st.cache_data
|
| 10 |
def load_geojson_data(file_paths):
|
| 11 |
geodata = []
|
| 12 |
for path in file_paths:
|
| 13 |
gdf = gpd.read_file(path)
|
|
|
|
|
|
|
| 14 |
geodata.append(gdf)
|
| 15 |
return geodata
|
| 16 |
|
| 17 |
-
# Sample Polygon GeoJSON
|
| 18 |
-
polygon_geojson = json.loads("""
|
| 19 |
-
{
|
| 20 |
-
"type": "FeatureCollection",
|
| 21 |
-
"features": [
|
| 22 |
-
{
|
| 23 |
-
"type": "Feature",
|
| 24 |
-
"properties": {"density": 10},
|
| 25 |
-
"geometry": {
|
| 26 |
-
"type": "Polygon",
|
| 27 |
-
"coordinates": [[[79.486114,27.577006],[79.5157554,27.5646727],[79.5405574,27.5461701],[79.5695939,27.519081],[79.5756432,27.4938634],[79.5593101,27.4871556],[79.5308786,27.5257868],[79.5003298,27.5319559],[79.4849041,27.5456337],[79.4761327,27.5652089],[79.486114,27.577006]]]
|
| 28 |
-
}
|
| 29 |
-
}
|
| 30 |
-
]
|
| 31 |
-
}
|
| 32 |
-
""")
|
| 33 |
-
|
| 34 |
-
# Sidebar
|
| 35 |
st.sidebar.title("Geospatial Data Visualization")
|
| 36 |
timestamp = st.sidebar.select_slider("Time", options=[f"{year}-01" for year in range(2016, 2024)])
|
| 37 |
|
| 38 |
-
|
| 39 |
-
st.title("
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
-
geojson_file_paths = ['chambal_centroids.geojson','kathajodi_centroids.geojson']
|
| 43 |
geojson_data = load_geojson_data(geojson_file_paths)
|
| 44 |
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
all_geo_data['lat']
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pydeck as pdk
|
|
|
|
| 3 |
import geopandas as gpd
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
|
|
|
|
| 7 |
@st.cache_data
|
| 8 |
def load_geojson_data(file_paths):
|
| 9 |
geodata = []
|
| 10 |
for path in file_paths:
|
| 11 |
gdf = gpd.read_file(path)
|
| 12 |
+
gdf['lon'] = gdf.geometry.x
|
| 13 |
+
gdf['lat'] = gdf.geometry.y
|
| 14 |
geodata.append(gdf)
|
| 15 |
return geodata
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
st.sidebar.title("Geospatial Data Visualization")
|
| 18 |
timestamp = st.sidebar.select_slider("Time", options=[f"{year}-01" for year in range(2016, 2024)])
|
| 19 |
|
| 20 |
+
|
| 21 |
+
st.title("Geospatial Data Visualization")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
geojson_file_paths = ['kathajodi_centroids.geojson','chambal_centroids.geojson']
|
| 25 |
|
| 26 |
|
|
|
|
| 27 |
geojson_data = load_geojson_data(geojson_file_paths)
|
| 28 |
|
| 29 |
|
| 30 |
+
all_geo_data = pd.concat(geojson_data)
|
| 31 |
+
all_geo_data['lon'] = all_geo_data.geometry.x
|
| 32 |
+
all_geo_data['lat'] = all_geo_data.geometry.y
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if 'view_state' not in st.session_state:
|
| 36 |
+
st.session_state.view_state = pdk.ViewState(
|
| 37 |
+
latitude=all_geo_data['lat'].mean(),
|
| 38 |
+
longitude=all_geo_data['lon'].mean(),
|
| 39 |
+
zoom=10,
|
| 40 |
+
pitch=45,
|
| 41 |
+
bearing=0
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
tab1, tab2 = st.tabs(["Heatmap", "3D Hexagon Plot"])
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
with tab1:
|
| 49 |
+
st.subheader("Heatmap View")
|
| 50 |
+
|
| 51 |
+
# Pydeck HeatmapLayer for Points
|
| 52 |
+
heatmap_layer = pdk.Layer(
|
| 53 |
+
"HeatmapLayer",
|
| 54 |
+
all_geo_data,
|
| 55 |
+
get_position=['lon', 'lat'],
|
| 56 |
+
aggregation=pdk.types.String("MEAN"),
|
| 57 |
+
opacity=0.5
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
r = pdk.Deck(
|
| 61 |
+
layers=[heatmap_layer],
|
| 62 |
+
initial_view_state=st.session_state.view_state,
|
| 63 |
+
map_style='mapbox://styles/mapbox/satellite-v9'
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
st.session_state.view_state = r.initial_view_state
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
st.pydeck_chart(r)
|
| 71 |
+
|
| 72 |
+
# Add an informational box
|
| 73 |
+
with st.expander("View Information"):
|
| 74 |
+
st.write(f"Selected Time: {timestamp}")
|
| 75 |
+
num_points = len(all_geo_data)
|
| 76 |
+
st.write(f"Number of Features: {num_points}")
|
| 77 |
+
|
| 78 |
+
# 3D Hexagon Plot Tab
|
| 79 |
+
with tab2:
|
| 80 |
+
st.subheader("3D Hexagon Map View")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
hexagon_layer = pdk.Layer(
|
| 84 |
+
"HexagonLayer",
|
| 85 |
+
all_geo_data,
|
| 86 |
+
get_position=['lon', 'lat'],
|
| 87 |
+
radius=200,
|
| 88 |
+
elevation_scale=20,
|
| 89 |
+
elevation_range=[0, 1000],
|
| 90 |
+
extruded=True,
|
| 91 |
+
coverage=1,
|
| 92 |
+
pickable=True
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
r = pdk.Deck(
|
| 97 |
+
layers=[hexagon_layer],
|
| 98 |
+
initial_view_state=st.session_state.view_state,
|
| 99 |
+
map_style='mapbox://styles/mapbox/satellite-v9'
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
st.session_state.view_state = r.initial_view_state
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
st.pydeck_chart(r)
|
| 107 |
+
|
| 108 |
+
# Add informational box
|
| 109 |
+
with st.expander("View Information"):
|
| 110 |
+
st.write(f"Selected Time: {timestamp}")
|
| 111 |
+
num_points = len(all_geo_data)
|
| 112 |
+
st.write(f"Number of Features: {num_points}")
|