-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmap1.py
More file actions
38 lines (31 loc) · 1.47 KB
/
Copy pathmap1.py
File metadata and controls
38 lines (31 loc) · 1.47 KB
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
import folium, pandas
# first create a map object
map = folium.Map(location=[38.58, -99], zoom_start=6, tiles='Stamen Terrain')
data = pandas.read_csv('Volcanoes_USA.txt')
fgv = folium.FeatureGroup(name='Volcanoes')
# convert the pandas series to python list
lat = list(data['LAT'])
lon = list(data['LON'])
elev = list(data['ELEV'])
def color_producer(elevation):
if elevation < 1500:
return 'green'
elif elevation < 3000:
return 'orange'
else:
return 'red'
for lt, ln, el in zip(lat, lon, elev):
fgv.add_child(folium.CircleMarker(location=[lt, ln], radius=6, fill=True, color='gray', fill_opacity=0.7,
fill_color=color_producer(el), popup=str(el)+" m"))
fgp = folium.FeatureGroup(name='Population')
# add another layer: the GeoJson object
# the x inside the lambda expression is 'feature' in geojson object ----can refer to the doc of folium library
fgp.add_child(folium.GeoJson(data=(open('world.json','r', encoding='utf-8-sig')).read(),
style_function=lambda x: {'fillColor': 'green' if x['properties']['POP2005'] < 10000000
else 'orange' if 10000000 <= x['properties']['POP2005'] < 20000000 else 'red'}))
map.add_child(fgp)
map.add_child(fgv)
# it's important to add the layer control object after we've added all feature group(s)
map.add_child(folium.LayerControl())
map.save('Map1.html')
# a function that determines the color of the marker based on elevation