-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeopandas_map.py
94 lines (90 loc) · 2.89 KB
/
geopandas_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import streamlit as st
import altair as alt
import geopandas as gpd
import json
st.header('Load from remote URL using alt.topo_feature')
code = '''
regions = alt.topo_feature("https://raw.githubusercontent.com/deldersveld/topojson/master/countries/italy/italy-regions.json", 'ITA_adm1')
map = alt.Chart(regions).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)
'''
st.code(code, language='python')
regions = alt.topo_feature("https://raw.githubusercontent.com/deldersveld/topojson/master/countries/italy/italy-regions.json", 'ITA_adm1')
map = alt.Chart(regions).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)
st.header('Load from local file using alt.InlineData')
code = '''
with open("italy-regions.json", 'r', encoding = 'utf-8') as f:
data = json.load(f)
regions_local = alt.InlineData(values=data, format=alt.DataFormat(feature='ITA_adm1',type='topojson'))
map = alt.Chart(regions_local).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)
'''
st.code(code, language='python')
with open("italy-regions.json", 'r', encoding = 'utf-8') as f:
data = json.load(f)
regions_local = alt.InlineData(values=data, format=alt.DataFormat(feature='ITA_adm1',type='topojson'))
map = alt.Chart(regions_local).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)
st.header('Load from local file using geopandas + alt.InlineData')
code = '''
regions_local = gpd.read_file("italy-regions.json")
data = alt.InlineData(values = regions_local.to_json(), format = alt.DataFormat(property='features', type='json'))
map = alt.Chart(data).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)
'''
st.code(code, language='python')
regions_local = gpd.read_file("italy-regions.json")
data = alt.InlineData(values = regions_local.to_json(), format = alt.DataFormat(property='features', type='json'))
map = alt.Chart(data).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)
st.header('Load from local file using geopandas')
code = '''
regions_local = gpd.read_file("italy-regions.json")
map = alt.Chart(regions_local).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)
'''
st.code(code, language='python')
regions_local = gpd.read_file("italy-regions.json")
map = alt.Chart(regions_local).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
st.altair_chart(map, use_container_width=False)