-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapa_redemet_cemaden.py
118 lines (88 loc) · 2.77 KB
/
mapa_redemet_cemaden.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import pandas as pd
import folium
def parse_coordinates(coord_str):
degrees = float(coord_str.split('º')[0])
minutes = float(coord_str.split('º')[1].split("'")[0])
seconds = float(coord_str.split("'")[1].split("''")[0])
direction = coord_str.split("'' ")[1]
decimal_degrees = degrees + minutes / 60 + seconds / 3600
if direction in ['S', 'W']:
decimal_degrees = -decimal_degrees
return decimal_degrees
def add_points_to_map(map_obj: folium.Map, df: pd.DataFrame, radius=5, color='blue', fill_opacity=0.6):
for _, row in df.iterrows():
folium.CircleMarker(
location=[row['lat'], row['long']],
radius=radius,
color=color,
fill_color=color,
fill_opacity=fill_opacity,
popup=f"{row['nome']}: {row['lat']}, {row['long']}",
).add_to(map_obj)
return map_obj
redemet_df = pd.DataFrame({
'nome': ['SBGL', 'SBJR', 'SBRJ', 'SBSC', 'SBAF'],
'lat': ["22º48'32'' S", "22º59'12'' S", "22º54'37'' S", "22º55'56'' S", "22º52'30'' S"],
'long': ["43º14'37'' W", "43º22'19'' W", "43º9'47'' W", "43º43'8'' W", "43º 23'4'' W"]
})
redemet_df['lat'] = redemet_df['lat'].apply(parse_coordinates)
redemet_df['long'] = redemet_df['long'].apply(parse_coordinates)
centroid = [-22.89181404239337, -43.269477142236386]
zoom_start = 11
tiles = "cartodbpositron"
_map = folium.Map(
location=centroid,
zoom_start=zoom_start,
tiles=tiles,
)
_map = add_points_to_map(
_map,
redemet_df,
color='darkgreen',
)
_map.save('mapa.html')
_map
cemaden_df = pd.read_csv("cemaden2.csv")
cemaden_df.tail()
print(cemaden_df)
cemaden_df = pd.read_csv("cemaden2.csv", usecols=['nome', 'lat', 'long'])
cemaden_df.columns = ['nome', 'lat', 'long']
cemaden_df.head()
required_columns = ['lat', 'long']
dataframes = [redemet_df, cemaden_df]
for df in dataframes:
for column in required_columns:
assert column in df.columns, f"Column '{column}' not found in DataFrame '{df}'"
_map =folium.Map(
location=centroid,
zoom_start=zoom_start,
tiles=tiles,
)
_map = add_points_to_map(
_map,
redemet_df,
color='darkred',
)
_map = add_points_to_map(
_map,
cemaden_df,
color='darkblue',
)
colors = ['red', 'blue']
labels = ['Redemet', 'Cemaden']
legend_html = '''
<div style="position: fixed;
bottom: 1px; right: 1px; width: 120px; height: 80px;
border:2px solid grey; z-index:9999; font-size:14px;
background-color: white;
">
'''
for i, label in enumerate(labels):
legend_html += f'''
<i class="fa fa-circle fa-1x" style="color:{colors[i]}"></i> {label}<br>
'''
legend_html += '</div>'
_map.get_root().html.add_child(folium.Element(legend_html))
_map
_map.save('mapaoficial.html')
_map