Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- .streamlit/config.toml +18 -0
- ISDMap.py +100 -0
- Intermediate_School_Districts.geojson +0 -0
- MTSS.ai_Logo.png +0 -0
- requirements.txt +8 -0
.streamlit/config.toml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
|
| 3 |
+
# Primary accent for interactive elements
|
| 4 |
+
primaryColor = "#00C649"
|
| 5 |
+
|
| 6 |
+
# Background color for the main content area
|
| 7 |
+
backgroundColor = "#FFFFFF"
|
| 8 |
+
|
| 9 |
+
# Background color for sidebar and most interactive widgets
|
| 10 |
+
secondaryBackgroundColor = "#F5F5F5"
|
| 11 |
+
|
| 12 |
+
# Color used for almost all text
|
| 13 |
+
textColor = "#2B4150"
|
| 14 |
+
|
| 15 |
+
# Font family for all text in the app, except code blocks
|
| 16 |
+
# Accepted values (serif | sans serif | monospace)
|
| 17 |
+
# Default: "sans serif"
|
| 18 |
+
font = "sans serif"
|
ISDMap.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import geopandas
|
| 4 |
+
import folium
|
| 5 |
+
from streamlit_folium import st_folium
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import tempfile
|
| 8 |
+
|
| 9 |
+
# Streamlit page setup
|
| 10 |
+
st.set_page_config(page_title="ISD Mapping", layout="centered", initial_sidebar_state="collapsed")
|
| 11 |
+
st.image('/Users/cheynelevesseur/Desktop/Python_Code/Mapping_Projects/ISD_Map/MTSS.ai_Logo.png', width=300) # Adjust path as needed
|
| 12 |
+
st.header('MTSS Maps™ | ISDs')
|
| 13 |
+
st.subheader('Map Generator')
|
| 14 |
+
|
| 15 |
+
# CSV file upload
|
| 16 |
+
# uploaded_file = st.file_uploader("Upload your ISD data CSV", type=["csv"])
|
| 17 |
+
# if uploaded_file is not None:
|
| 18 |
+
# df = pd.read_csv(uploaded_file)
|
| 19 |
+
|
| 20 |
+
# Excel file upload
|
| 21 |
+
uploaded_file = st.file_uploader("Upload your ISD data XLSX", type=["xlsx"])
|
| 22 |
+
if uploaded_file is not None:
|
| 23 |
+
# Specify dtype as str for 'ISD Code' to ensure it reads in as string
|
| 24 |
+
df = pd.read_excel(uploaded_file, dtype={"ISD Code": str})
|
| 25 |
+
|
| 26 |
+
# Add column "Count" and add 1 to all rows
|
| 27 |
+
df['Count'] = 1
|
| 28 |
+
|
| 29 |
+
# If the 'ISD Code' column contains integers without leading zeros, add them
|
| 30 |
+
df['ISD Code'] = df['ISD Code'].apply(lambda x: str(x).zfill(5))
|
| 31 |
+
|
| 32 |
+
# Load GeoJSON file from the root directory
|
| 33 |
+
geojson_filename = "Intermediate_School_Districts.geojson" # Name of your GeoJSON file
|
| 34 |
+
geojson_path = Path(__file__).parent / geojson_filename # Construct the path to the GeoJSON file
|
| 35 |
+
|
| 36 |
+
if geojson_path.exists():
|
| 37 |
+
Mi_ISD_geojson = geopandas.read_file(str(geojson_path))
|
| 38 |
+
Mi_ISD_geojson.rename(columns={'ISD': 'ISD Code', 'NAME': 'ISD'}, inplace=True)
|
| 39 |
+
|
| 40 |
+
# Drop unwanted columns
|
| 41 |
+
columns_to_drop = ['OBJECTID', 'LABEL', 'TYPE', 'SQKM', 'SQMILES', 'ACRES', 'VER','LAYOUT', 'PENINSULA', 'ISDCode', 'ISD1', 'ShapeSTArea', 'ShapeSTLength']
|
| 42 |
+
Mi_ISD_geojson.drop(columns=columns_to_drop, axis=1, inplace=True)
|
| 43 |
+
|
| 44 |
+
# Ensure 'ISD Code' is treated as a string to preserve leading zeros
|
| 45 |
+
Mi_ISD_geojson['ISD Code'] = Mi_ISD_geojson['ISD Code'].astype(str)
|
| 46 |
+
|
| 47 |
+
# If the 'ISD Code' column contains integers without leading zeros, add them
|
| 48 |
+
Mi_ISD_geojson['ISD Code'] = Mi_ISD_geojson['ISD Code'].apply(lambda x: str(x).zfill(5))
|
| 49 |
+
|
| 50 |
+
# Merge GeoJSON file and DataFrame
|
| 51 |
+
ISD_Combined = pd.merge(Mi_ISD_geojson, df, on='ISD Code', how='left', suffixes=('', '_drop')).fillna(0)
|
| 52 |
+
|
| 53 |
+
# Identify any columns that end with '_drop' and drop them
|
| 54 |
+
ISD_Combined = ISD_Combined.loc[:, ~ISD_Combined.columns.str.endswith('_drop')]
|
| 55 |
+
|
| 56 |
+
# Generating the Folium map
|
| 57 |
+
def style_function(feature):
|
| 58 |
+
count = feature['properties'].get('Count', 0)
|
| 59 |
+
return {
|
| 60 |
+
'fillColor': '#48BB88' if count > 0 else 'white',
|
| 61 |
+
'color': 'black',
|
| 62 |
+
'weight': 0.15,
|
| 63 |
+
'fillOpacity': 0.7 if count > 0 else 0.25,
|
| 64 |
+
'lineOpacity': 0.4,
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
m = folium.Map(location=[44.3148, -85.6024], zoom_start=7)
|
| 68 |
+
folium.GeoJson(
|
| 69 |
+
ISD_Combined.to_json(),
|
| 70 |
+
style_function=style_function,
|
| 71 |
+
tooltip=folium.GeoJsonTooltip(fields=['ISD'], aliases=['ISD:'])
|
| 72 |
+
).add_to(m)
|
| 73 |
+
|
| 74 |
+
# call to render Folium map in Streamlit
|
| 75 |
+
st_data = st_folium(m, width=725)
|
| 76 |
+
|
| 77 |
+
# Save the map to a temporary HTML file and offer it for download
|
| 78 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
|
| 79 |
+
m.save(tmpfile.name)
|
| 80 |
+
tmpfile.seek(0)
|
| 81 |
+
with open(tmpfile.name, "rb") as file:
|
| 82 |
+
btn = st.download_button(
|
| 83 |
+
label="Download Map as HTML",
|
| 84 |
+
data=file,
|
| 85 |
+
file_name="District_Map.html",
|
| 86 |
+
mime="text/html"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Displaying ISDs with a count of 1
|
| 90 |
+
ISDs_with_one = ISD_Combined[ISD_Combined['Count'] == 1]
|
| 91 |
+
if not ISDs_with_one.empty:
|
| 92 |
+
st.write("ISDs:")
|
| 93 |
+
# st.dataframe(ISDs_with_one[['ISD', 'ISD Code']])
|
| 94 |
+
st.dataframe(ISDs_with_one[['ISD', 'ISD Code']].reset_index(drop=True))
|
| 95 |
+
|
| 96 |
+
# Informing the user about the total number of ISD with a count of 1
|
| 97 |
+
total_ISDs_with_one = len(ISDs_with_one)
|
| 98 |
+
st.write(f"Total number of ISD: {total_ISDs_with_one}")
|
| 99 |
+
else:
|
| 100 |
+
st.write("No ISD have a count of 1.")
|
Intermediate_School_Districts.geojson
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
MTSS.ai_Logo.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
geopandas
|
| 4 |
+
folium
|
| 5 |
+
fiona
|
| 6 |
+
pyogrio # Optional, if you decide to use it as an alternative to fiona
|
| 7 |
+
streamlit_folium
|
| 8 |
+
openpyxl
|