Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,108 +1,38 @@
|
|
1 |
import folium
|
2 |
|
3 |
-
|
4 |
-
birds = [
|
5 |
-
{
|
6 |
-
'species': 'Canada Goose',
|
7 |
-
'lat': 44.9778,
|
8 |
-
'lon': -93.2650,
|
9 |
-
'start_month': 'September',
|
10 |
-
'end_month': 'April'
|
11 |
-
},
|
12 |
-
{
|
13 |
-
'species': 'Mallard Duck',
|
14 |
-
'lat': 44.8835,
|
15 |
-
'lon': -93.2273,
|
16 |
-
'start_month': 'August',
|
17 |
-
'end_month': 'May'
|
18 |
-
},
|
19 |
-
{
|
20 |
-
'species': 'Wood Duck',
|
21 |
-
'lat': 44.9778,
|
22 |
-
'lon': -93.2650,
|
23 |
-
'start_month': 'March',
|
24 |
-
'end_month': 'November'
|
25 |
-
},
|
26 |
-
{
|
27 |
-
'species': 'Trumpeter Swan',
|
28 |
-
'lat': 45.0941,
|
29 |
-
'lon': -94.2392,
|
30 |
-
'start_month': 'October',
|
31 |
-
'end_month': 'April'
|
32 |
-
},
|
33 |
-
{
|
34 |
-
'species': 'Tundra Swan',
|
35 |
-
'lat': 44.9358,
|
36 |
-
'lon': -93.1553,
|
37 |
-
'start_month': 'November',
|
38 |
-
'end_month': 'April'
|
39 |
-
},
|
40 |
-
{
|
41 |
-
'species': 'Canvasback',
|
42 |
-
'lat': 44.8835,
|
43 |
-
'lon': -93.2273,
|
44 |
-
'start_month': 'September',
|
45 |
-
'end_month': 'May'
|
46 |
-
},
|
47 |
-
{
|
48 |
-
'species': 'Redhead',
|
49 |
-
'lat': 44.9778,
|
50 |
-
'lon': -93.2650,
|
51 |
-
'start_month': 'September',
|
52 |
-
'end_month': 'May'
|
53 |
-
},
|
54 |
-
{
|
55 |
-
'species': 'Greater Scaup',
|
56 |
-
'lat': 44.8835,
|
57 |
-
'lon': -93.2273,
|
58 |
-
'start_month': 'September',
|
59 |
-
'end_month': 'May'
|
60 |
-
},
|
61 |
-
{
|
62 |
-
'species': 'Lesser Scaup',
|
63 |
-
'lat': 44.9778,
|
64 |
-
'lon': -93.2650,
|
65 |
-
'start_month': 'September',
|
66 |
-
'end_month': 'May'
|
67 |
-
},
|
68 |
-
{
|
69 |
-
'species': 'Hooded Merganser',
|
70 |
-
'lat': 44.8835,
|
71 |
-
'lon': -93.2273,
|
72 |
-
'start_month': 'October',
|
73 |
-
'end_month': 'April'
|
74 |
-
}
|
75 |
-
]
|
76 |
-
|
77 |
-
# Create a Folium map with the initial location and zoom level
|
78 |
-
m = folium.Map(location=[44.9778, -93.2650], zoom_start=8)
|
79 |
-
|
80 |
-
# Add markers for each bird species
|
81 |
-
for bird in birds:
|
82 |
-
# Get the species, latitude, longitude, start month, and end month from the dictionary
|
83 |
species = bird['species']
|
84 |
lat = bird['lat']
|
85 |
lon = bird['lon']
|
86 |
start_month = bird['start_month']
|
87 |
end_month = bird['end_month']
|
88 |
-
|
89 |
-
# Create a popup message for the marker
|
90 |
popup_msg = f"{species}: {start_month} - {end_month}"
|
91 |
-
|
92 |
-
# Add a marker to the map with the latitude, longitude, and popup message
|
93 |
-
marker = folium.Marker(location=[lat, lon], popup=popup_msg)
|
94 |
-
|
95 |
-
# Add the species, start month, and end month to the marker icon
|
96 |
icon_text = f"{species} ({start_month} - {end_month})"
|
97 |
icon = folium.Icon(color='red', icon='glyphicon-map-marker', prefix='glyphicon')
|
|
|
98 |
marker.add_child(folium.Popup(icon_text))
|
99 |
-
marker
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
|
|
|
|
|
|
|
|
|
1 |
import folium
|
2 |
|
3 |
+
def create_marker(bird):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
species = bird['species']
|
5 |
lat = bird['lat']
|
6 |
lon = bird['lon']
|
7 |
start_month = bird['start_month']
|
8 |
end_month = bird['end_month']
|
|
|
|
|
9 |
popup_msg = f"{species}: {start_month} - {end_month}"
|
|
|
|
|
|
|
|
|
|
|
10 |
icon_text = f"{species} ({start_month} - {end_month})"
|
11 |
icon = folium.Icon(color='red', icon='glyphicon-map-marker', prefix='glyphicon')
|
12 |
+
marker = folium.Marker(location=[lat, lon], popup=popup_msg)
|
13 |
marker.add_child(folium.Popup(icon_text))
|
14 |
+
return marker
|
15 |
+
|
16 |
+
def create_map(center, zoom, markers):
|
17 |
+
m = folium.Map(location=center, zoom_start=zoom)
|
18 |
+
for marker in markers:
|
19 |
+
marker.add_to(m)
|
20 |
+
return m
|
|
|
21 |
|
22 |
+
birds = [
|
23 |
+
{'species': 'Canada Goose', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'April'},
|
24 |
+
{'species': 'Mallard Duck', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'August', 'end_month': 'May'},
|
25 |
+
{'species': 'Wood Duck', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'March', 'end_month': 'November'},
|
26 |
+
{'species': 'Trumpeter Swan', 'lat': 45.0941, 'lon': -94.2392, 'start_month': 'October', 'end_month': 'April'},
|
27 |
+
{'species': 'Tundra Swan', 'lat': 44.9358, 'lon': -93.1553, 'start_month': 'November', 'end_month': 'April'},
|
28 |
+
{'species': 'Canvasback', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'},
|
29 |
+
{'species': 'Redhead', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'},
|
30 |
+
{'species': 'Greater Scaup', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'},
|
31 |
+
{'species': 'Lesser Scaup', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'},
|
32 |
+
{'species': 'Hooded Merganser', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'October', 'end_month': 'April'}
|
33 |
+
]
|
34 |
|
35 |
+
markers = [create_marker(bird) for bird in birds]
|
36 |
+
center = [44.9778, -93.2650]
|
37 |
+
zoom = 8
|
38 |
+
create_map(center, zoom, markers)
|