import streamlit as st from streamlit_folium import st_folium import folium import glob import geopandas as gpd import pandas as pd import pathlib if __name__ == "__main__": """ # Lithos Carbon Shapefile Viewer """ # glob shapefiles to load current_dir = pathlib.Path().resolve() data_dir = current_dir / "data" shapefiles_list = sorted(data_dir.glob("*.shp")) # user selects which shapefiels to plot selected_shapefiles = st.pills("Choose shapefiles to view on the map", shapefiles_list, selection_mode="multi") # load and merge shapefiles if selected_shapefiles: gdf = gpd.GeoDataFrame() gdf = gpd.GeoDataFrame(pd.concat([gpd.read_file(i) for i in selected_shapefiles], ignore_index=True), crs=gpd.read_file(selected_shapefiles[0]).crs) # Create a Folium map m = folium.Map(location=[gdf.centroid.y.mean(), gdf.centroid.x.mean()], zoom_start=13) folium.GeoJson(gdf.to_json()).add_to(m) # Display the map in Streamlit st_folium(m) # Display data in table format st.write(gdf)