It is a map-based app that takes a shape file and converts it into Google geocode areas before showing the results on a map.
Drop files here
or click to upload
import streamlit as st
import geopandas as gpd
import pandas as pd
from shapely.geometry import Point, Polygon
import json
st.title("Shapefile to Map Viewer")
# File uploader for shapefile
uploaded_file = st.file_uploader("Choose a Shapefile (.shp)", type=['shp'])
if uploaded_file is not None:
try:
# Read the shapefile
gdf = gpd.read_file(uploaded_file)
# Convert CRS to WGS84 (standard lat/long)
if gdf.crs is not None and gdf.crs != 'EPSG:4326':
gdf = gdf.to_crs('EPSG:4326')
# Create a DataFrame with the centroid coordinates
df_for_map = pd.DataFrame()
df_for_map['latitude'] = gdf.geometry.centroid.y
df_for_map['longitude'] = gdf.geometry.centroid.x
# Display the GeoDataFrame info
st.subheader("Shapefile Information")
st.write(f"Number of features: {len(gdf)}")
st.write(f"Coordinate Reference System: {gdf.crs}")
# Display the attribute table
st.subheader("Attribute Table")
st.dataframe(gdf.drop('geometry', axis=1))
# Display the map
st.subheader("Map Visualization")
st.map(df_for_map)
# Display GeoJSON for debugging
if st.checkbox("Show GeoJSON"):
st.json(json.loads(gdf.to_json()))
except Exception as e:
st.error(f"Error processing shapefile: {str(e)}")
else:
st.info("Please upload a shapefile (.shp) to begin.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?