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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -56
app.py CHANGED
@@ -1,58 +1,23 @@
 
1
  import streamlit as st
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)
 
1
+ import altair as alt
2
  import streamlit as st
 
 
 
 
 
3
 
4
+ african_countries = alt.topo_feature(
5
+ "https://raw.githubusercontent.com/deldersveld/topojson/master/continents/africa.json",
6
+ "continent_Africa_subunits",
7
+ )
8
+ africa_chart = (
9
+ alt.Chart(african_countries)
10
+ .mark_geoshape(stroke="white", strokeWidth=2)
11
+ .encode(
12
+ color="value:Q",
13
+ tooltip=[
14
+ alt.Tooltip("properties.geounit:O", title="Country name"),
15
+ alt.Tooltip("value:Q", title="Indicator value"),
16
+ ],
17
+ )
18
+ .transform_lookup(
19
+ lookup="properties.geounit",
20
+ from_=alt.LookupData(filtered_data, "Geo Name", ["value"]),
21
+ )
22
+ )
23
+ st.altair_chart(africa_chart)