-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_map.py
60 lines (54 loc) · 2.37 KB
/
make_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
import folium
from read_list import read
import pandas
# make a map zoomed to see all the countries
map = folium.Map(location=[20, -3], zoom_start=2.52)
# make a feature group that will place the markers
# on the location of directed films
fg = folium.FeatureGroup(name="Films")
places = read()
for k, v in places.items():
str = ""
for i in v:
str += i + "\n"
popup_res = folium.Popup(str, parse_html=True)
fg.add_child(folium.Marker(location=k, popup=popup_res,
icon=folium.Icon()))
# make a dictionary that has country as key and rate as value
data_cancer = pandas.read_csv("cancer.csv")
country = data_cancer["country"]
rate = data_cancer["rate"]
csv_dict = {}
for k, v in zip(country, rate):
csv_dict[k] = v
# make a feature group that will color the map depending
# on age-standardized rates of incident cases,
# both sexes, all cancers excluding non-melanoma
# skin cancer, worldwide in 2012
fg_cc = folium.FeatureGroup(name="Cancer_rate")
fg_cc.add_child(folium.GeoJson(data=open('world.json', 'r',
encoding='utf-8-sig').read(),
style_function=lambda x: {'fillColor': 'red' if
(x['properties']['NAME'] in csv_dict.keys() and
csv_dict[x['properties']['NAME']] > 244.2)
else 'green' if
x['properties']['NAME'] in csv_dict.keys() and
(140 < csv_dict[x['properties']['NAME']] < 244)
else "blue" if (x['properties']['NAME'] in
csv_dict.keys() and
(csv_dict[x['properties']['NAME']] > 100 and
csv_dict[x['properties']['NAME']] < 140))
else 'grey'}))
print("In addition to the markers that point on location "
"where the films were directed," + "\n"
"the map shows age-standardized rates of "
"incident cases, both sexes, " + "\n"
"all cancers excluding non-melanoma skin cancer, "
"worldwide in 2012" + "\n"
"(red - > 244.2, green - < 244.2 and > 140, "
"blue < 140 and > 100, " + "\n"
"grey - no data or not applicable)")
map.add_child(fg_cc)
map.add_child(fg)
map.add_child(folium.LayerControl())
map.save("Rybka_map.html")