In [1]:
from IPython.display import display
from folium.element import IFrame
from folium.plugins import MarkerCluster
from folium import GeoJson
import glob
import folium
import json
import random
print(folium.__version__)
In [2]:
mapa = folium.Map(location=[-20, -30], zoom_start=4)
for fname in glob.glob('../data/estados_2010-*.json'):
with open(fname) as f:
data = json.load(f)
# add style info
color = "#%03x" % random.randint(0, 0xFFF)
data['features'][0]['properties']['stroke'] = color
data['features'][0]['properties']['stroke-width'] = 1.5
data['features'][0]['properties']['fill'] = color
# create geojson object
gj = GeoJson(
data, style_function=lambda x: {
'color' : x['properties']['stroke'],
'weight' : x['properties']['stroke-width'],
'opacity': 0.6,
'fillColor' : x['properties']['fill'],
})
gj.layer_name = gj.data['features'][0]['properties']['nome']
gj.add_to(mapa)
# FIXME: active=False by default.None
mapa.add_children(folium.LayerControl())
mapa
Out[2]:
Author: Ivan Ogasawara
This work is licensed under a Creative Commons Attribution 4.0 International License .
How to plot colored polygons: http://stackoverflow.com/questions/35516318/plot-colored-polygons-with-geodataframe-in-folium
Brazil shape files: http://www.codegeo.com.br/2013/04/shapefiles-do-brasil-para-download.html