In [10]:
import pandas as pd
import geopandas as gpd
import folium
import shapely
import matplotlib.pyplot as plt
from shapely.ops import unary_union
%matplotlib inline
In [17]:
gdf = gpd.GeoDataFrame.from_file("DEPARTEMENT/DEPARTEMENT.shp")
gdf.head()
Out[17]:
In [18]:
json = gdf.to_json()
In [19]:
with open("DEPARTEMENT/dep.geojson", "w") as f:
f.write(json)
In [20]:
from bokeh.io import show, output_notebook
from bokeh.models import GeoJSONDataSource, HoverTool, LinearColorMapper
from bokeh.plotting import figure
from bokeh.palettes import Viridis256
output_notebook()
In [22]:
with open(r'DEPARTEMENT/dep.geojson') as f:
geo_src = GeoJSONDataSource(geojson=f.read())
In [23]:
cmap = LinearColorMapper(palette=Viridis256)
In [25]:
type(GeoJSONDataSource)
Out[25]:
In [24]:
TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"
p = figure(title='France Département', tools=TOOLS, x_axis_location=None, y_axis_location=None, width=500, height=500)
p.grid.grid_line_color = None
p.patches('xs', 'ys', fill_alpha=0.7, fill_color={'field': 'CODE_DEPT', 'transform': cmap},
line_color='black', line_width=0.5, source=geo_src)
hover = p.select_one(HoverTool)
hover.point_policy = 'follow_mouse'
hover.tooltips = [('Département:', '@NOM_DEPT')]
show(p)