|
import streamlit as st |
|
import json |
|
import geopandas as gpd |
|
import pyproj |
|
import plotly.graph_objs as go |
|
polygon = gpd.read_file(r"\Downloads\CityBoundaries.shp") |
|
|
|
|
|
map_df = polygon |
|
map_df.to_crs(pyproj.CRS.from_epsg(4326), inplace=True) |
|
|
|
|
|
points = gpd.read_file(r"Downloads\USA_Major_Cities.shp") |
|
|
|
|
|
points.to_crs(pyproj.CRS.from_epsg(4326), inplace=True) |
|
|
|
|
|
Lat = points['Lat'] |
|
Long = points['Long'] |
|
|
|
|
|
path = r"C:\Users\project\geojson.json" |
|
|
|
map_df.to_file(path, driver = "GeoJSON") |
|
with open(path) as geofile: |
|
j_file = json.load(geofile) |
|
|
|
|
|
i=1 |
|
for feature in j_file["features"]: |
|
feature ['id'] = str(i).zfill(2) |
|
i += 1 |
|
|
|
|
|
mapboxt = 'MapBox Token' |
|
|
|
|
|
choro = go.Choroplethmapbox(z=map_df['STFIPS'], locations = map_df.index, colorscale = 'Viridis', geojson = j_file, text = map_df['NAME'], marker_line_width=0.1) |
|
|
|
|
|
|
|
scatt = go.Scattermapbox(lat=Lat,lon=Long,mode='markers+text',below='False', marker=dict( size=12, color ='rgb(56, 44, 100)')) |
|
|
|
|
|
layout = go.Layout(title_text ='USA Cities', title_x =0.5, width=950, height=700,mapbox = dict(center= dict(lat=37, lon=-95),accesstoken= mapboxt, zoom=4,style="stamen-terrain")) |
|
|
|
|
|
|
|
layer1 = st.multiselect('Layer Selection', [choro, scatt], format_func=lambda x: 'Polygon' if x==choro else 'Points') |
|
|
|
|
|
|
|
fig = go.Figure(data=layer1, layout=layout) |
|
|
|
|
|
|
|
st.plotly_chart(fig) |