fschwartzer commited on
Commit
59fd337
1 Parent(s): e38d8ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -10,17 +10,24 @@ import folium
10
  from branca.colormap import LinearColormap
11
 
12
  # Function to add heatmap layer to folium map
13
- def add_heatmap_layer(map_obj, filtered_data, column_name, colormap_name, radius=15):
14
- heat_data = filtered_data[['latitude', 'longitude', column_name]].dropna()
15
-
16
- cmap = LinearColormap(colors=['#9e0142', '#d53e4f', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#e6f598', '#abdda4', '#66c2a5', '#3288bd', '#5e4fa2'], vmin=heat_data[column_name].min(), vmax=heat_data[column_name].max())
17
-
18
- # Handle NaN values
19
- heat_data = heat_data[~np.isnan(heat_data[column_name])]
20
-
21
- heat_points = heat_data.apply(lambda row: [row['latitude'], row['longitude'], cmap(row[column_name])], axis=1).tolist()
22
-
23
- folium.plugins.HeatMap(heat_points, radius=radius, gradient={0.0: 'blue', 1.0: 'red'}).add_to(map_obj)
 
 
 
 
 
 
 
24
 
25
  # Function to calculate distance in meters between two coordinates
26
  def calculate_distance(lat1, lon1, lat2, lon2):
@@ -252,9 +259,9 @@ with st.container():
252
  folium_layermap = folium.Map(location=[custom_lat, custom_lon], zoom_start=zoom_level, control_scale=True)
253
 
254
  # Add heatmap layers for 'Valor_Urb', 'Valor_Eqp', and 'RENDA'
255
- add_heatmap_layer(folium_layermap, filtered_data, 'Valor_Urb', 'RdBu_r', radius=15)
256
- add_heatmap_layer(folium_layermap, filtered_data, 'Valor_Eqp', 'RdBu_r', radius=15)
257
- add_heatmap_layer(folium_layermap, filtered_data, 'RENDA', 'RdBu_r', radius=15)
258
 
259
  # Add layer control
260
  folium.LayerControl().add_to(folium_layermap)
 
10
  from branca.colormap import LinearColormap
11
 
12
  # Function to add heatmap layer to folium map
13
+ def add_heatmap_layer(map_obj, data, column_name, colormap_name, radius=15):
14
+ heat_data = data[['latitude', 'longitude', column_name]].dropna()
15
+ heat_layer = folium.FeatureGroup(name=f'Heatmap - {column_name}')
16
+
17
+ cmap = LinearColormap(colors=['blue', 'white', 'red'], vmin=heat_data[column_name].min(), vmax=heat_data[column_name].max())
18
+
19
+ for index, row in heat_data.iterrows():
20
+ folium.CircleMarker(
21
+ location=[row['latitude'], row['longitude']],
22
+ radius=radius,
23
+ fill=True,
24
+ fill_color=cmap(row[column_name]),
25
+ fill_opacity=0.7,
26
+ color='black',
27
+ weight=0.5,
28
+ ).add_to(heat_layer)
29
+
30
+ heat_layer.add_to(map_obj)
31
 
32
  # Function to calculate distance in meters between two coordinates
33
  def calculate_distance(lat1, lon1, lat2, lon2):
 
259
  folium_layermap = folium.Map(location=[custom_lat, custom_lon], zoom_start=zoom_level, control_scale=True)
260
 
261
  # Add heatmap layers for 'Valor_Urb', 'Valor_Eqp', and 'RENDA'
262
+ add_heatmap_layer(folium_layermap, filtered_data, 'Valor_Urb', 'RdBu_r')
263
+ add_heatmap_layer(folium_layermap, filtered_data, 'Valor_Eqp', 'RdBu_r')
264
+ add_heatmap_layer(folium_layermap, filtered_data, 'RENDA', 'RdBu_r')
265
 
266
  # Add layer control
267
  folium.LayerControl().add_to(folium_layermap)