import folium
import branca.colormap as cm
from branca.element import Element
# Create a new colormap with specified intervals
colormap = cm.StepColormap(
colors=['#2ECC71', '#3498DB', '#F1C40F', '#E67E22', '#E74C3C'],
vmin=autoturisme_grupate['TOTAL_VEHICULE'].min(),
vmax=autoturisme_grupate['TOTAL_VEHICULE'].max(),
index=[0, 100000, 150000, 200000, 500000, 1000000],
caption='Total Autoturisme per Județ'
)
# Create a new folium map centered on Romania
m = folium.Map(location=[45.9432, 24.9668], zoom_start=7)
# Function to style each feature and include the total vehicles in the tooltip
def style_function(feature):
judet = feature['properties']['name']
total_vehicule = autoturisme_grupate.loc[autoturisme_grupate['name'] == judet, 'TOTAL_VEHICULE'].values[0]
return {
'fillColor': colormap(total_vehicule),
'color': 'black',
'weight': 0.5,
'fillOpacity': 0.7,
}
# Add the GeoJson layer with tooltips
for feature in geojson_data['features']:
judet = feature['properties']['name']
total_vehicule = autoturisme_grupate.loc[autoturisme_grupate['name'] == judet, 'TOTAL_VEHICULE'].values[0]
tooltip = folium.Tooltip(f"{judet}: {total_vehicule} autoturisme")
folium.GeoJson(
feature,
style_function=style_function,
tooltip=tooltip
).add_to(m)
# Create a custom legend
legend_html = """
Total Autoturisme per Județ
< 100,000
100,000 - 150,000
150,000 - 200,000
200,000 - 500,000
> 500,000
"""
# Add the custom legend to the map
m.get_root().html.add_child(Element(legend_html))
# Save the map to an HTML file
map_path = '/mnt/data/harta_autoturisme_romania_v6.html'
m.save(map_path)
map_path