from os.path import join
import leafmap.foliumap as leafmap
import streamlit as st
import geopandas as gpd
st.set_page_config(layout="wide")
file_map = {"Ahmedabad 10 km buffer": "ahmedabad_10km_buffer.geojson",
"Lucknow 60x60 km Airshed": "lucknow_airshed.geojson",
"Delhi 80x80 km Airshed": "delhi_airshed.geojson",
"West Bengal small Airshed": "wb_small_airshed.geojson",
}
# st.title("Brick Kilns Interactive Map")
st.markdown(
f"""
Brick Kilns Interactive Map
""",
unsafe_allow_html=True,
)
region = st.selectbox("Select a region", list(file_map.keys()))
def style_function(feature):
class_name = feature['properties']['class_name']
if class_name == "Zigzag":
return {'color': 'green', 'weight': 3, 'fillColor': 'green', 'fillOpacity': 0}
elif class_name == "FCBK":
return {'color': 'orange', 'weight': 3, 'fillColor': 'orange', 'fillOpacity': 0}
elif class_name == "CFCBK":
return {'color': 'red', 'weight': 3, 'fillColor': 'red', 'fillOpacity': 0}
else:
return {'color': 'black', 'weight': 3, 'fillColor': 'black', 'fillOpacity': 0}
gdf = gpd.read_file(join("labels", file_map[region]))
# fill the horizontal space with table
mapping = {"CFCBK": "Circular Fixed Chimney Bull's Trench Kiln (CFCBK)",
"FCBK": "Fixed Chimney Bull's Trench Kiln (FCBK)",
"Zigzag": "Zigzag Kiln"}
gdf['class_name'] = gdf['class_name'].apply(lambda x: mapping[x])
counts = gdf['class_name'].value_counts()
# add Total
counts['Total'] = counts.sum()
st.table(counts)
m = leafmap.Map()
m.add_basemap("SATELLITE")
legend_dict = {"CFCBK": "red", "FCBK": "orange", "Zigzag": "green", "Region of Interest": "blue"}
m.add_geojson(join("shapes", file_map[region]), layer_name="Region of Interest")
m.add_geojson(join("labels", file_map[region]), style_function=style_function, layer_name="Kilns")
m.add_legend(legend_dict=legend_dict, title="Brick Kilns")
m.to_streamlit()