StreamlitApp / app.py
Jakecole1's picture
Update app.py
67fd68e verified
raw
history blame
2.68 kB
import streamlit as st
import pydeck as pdk
import geopandas as gpd
import pandas as pd
@st.cache_data
def load_geojson_data(file_paths):
geodata = []
for path in file_paths:
gdf = gpd.read_file(path)
gdf['lon'] = gdf.geometry.x
gdf['lat'] = gdf.geometry.y
geodata.append(gdf)
return geodata
st.sidebar.title("Geospatial Data Visualization")
timestamp = st.sidebar.select_slider("Time", options=[f"{year}-01" for year in range(2016, 2024)])
st.title("Geospatial Data Visualization")
geojson_file_paths = ['kathajodi_centroids.geojson','chambal_centroids.geojson']
geojson_data = load_geojson_data(geojson_file_paths)
all_geo_data = pd.concat(geojson_data)
all_geo_data['lon'] = all_geo_data.geometry.x
all_geo_data['lat'] = all_geo_data.geometry.y
if 'view_state' not in st.session_state:
st.session_state.view_state = pdk.ViewState(
latitude=all_geo_data['lat'].mean(),
longitude=all_geo_data['lon'].mean(),
zoom=10,
pitch=45,
bearing=0
)
tab1, tab2 = st.tabs(["Heatmap", "3D Hexagon Plot"])
with tab1:
st.subheader("Heatmap View")
# Pydeck HeatmapLayer for Points
heatmap_layer = pdk.Layer(
"HeatmapLayer",
all_geo_data,
get_position=['lon', 'lat'],
aggregation=pdk.types.String("MEAN"),
opacity=0.5
)
r = pdk.Deck(
layers=[heatmap_layer],
initial_view_state=st.session_state.view_state,
map_style='mapbox://styles/mapbox/satellite-v9'
)
st.session_state.view_state = r.initial_view_state
st.pydeck_chart(r)
# Add an informational box
with st.expander("View Information"):
st.write(f"Selected Time: {timestamp}")
num_points = len(all_geo_data)
st.write(f"Number of Features: {num_points}")
# 3D Hexagon Plot Tab
with tab2:
st.subheader("3D Hexagon Map View")
hexagon_layer = pdk.Layer(
"HexagonLayer",
all_geo_data,
get_position=['lon', 'lat'],
radius=1000,
elevation_scale=20,
elevation_range=[0, 1000],
extruded=True,
coverage=1,
pickable=True
)
r = pdk.Deck(
layers=[hexagon_layer],
initial_view_state=st.session_state.view_state,
map_style='mapbox://styles/mapbox/satellite-v9'
)
st.session_state.view_state = r.initial_view_state
st.pydeck_chart(r)
# Add informational box
with st.expander("View Information"):
st.write(f"Selected Time: {timestamp}")
num_points = len(all_geo_data)
st.write(f"Number of Features: {num_points}")