MadhuV28 commited on
Commit
088de9e
1 Parent(s): ab5f8ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -1
app.py CHANGED
@@ -2,4 +2,57 @@ import streamlit as st
2
  import json
3
  import geopandas as gpd
4
  import pyproj
5
- import plotly.graph_objs as go
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import json
3
  import geopandas as gpd
4
  import pyproj
5
+ import plotly.graph_objs as go
6
+ polygon = gpd.read_file(r"\Downloads\CityBoundaries.shp")
7
+
8
+ # project geopandas dataframe
9
+ map_df = polygon
10
+ map_df.to_crs(pyproj.CRS.from_epsg(4326), inplace=True)
11
+
12
+ # reading in the points shapefile
13
+ points = gpd.read_file(r"Downloads\USA_Major_Cities.shp")
14
+
15
+ # project geopandas dataframe
16
+ points.to_crs(pyproj.CRS.from_epsg(4326), inplace=True)
17
+
18
+ # define lat, long for ponints
19
+ Lat = points['Lat']
20
+ Long = points['Long']
21
+
22
+ # leases to geojson
23
+ path = r"C:\Users\project\geojson.json"
24
+
25
+ map_df.to_file(path, driver = "GeoJSON")
26
+ with open(path) as geofile:
27
+ j_file = json.load(geofile)
28
+
29
+ #index geojson
30
+ i=1
31
+ for feature in j_file["features"]:
32
+ feature ['id'] = str(i).zfill(2)
33
+ i += 1
34
+
35
+ # mapbox token
36
+ mapboxt = 'MapBox Token'
37
+
38
+ # define layers and plot map
39
+ 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)
40
+ # Your choropleth data here
41
+
42
+
43
+ scatt = go.Scattermapbox(lat=Lat,lon=Long,mode='markers+text',below='False', marker=dict( size=12, color ='rgb(56, 44, 100)'))
44
+ # Your scatter data here
45
+
46
+ 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"))
47
+
48
+
49
+ # streamlit multiselect widget
50
+ layer1 = st.multiselect('Layer Selection', [choro, scatt], format_func=lambda x: 'Polygon' if x==choro else 'Points')
51
+
52
+
53
+ #st.write('Layer 1:', layer1)
54
+ fig = go.Figure(data=layer1, layout=layout)
55
+
56
+
57
+ # display streamlit
58
+ st.plotly_chart(fig)