Gdf2Bokeh¶
Gdf2Bokeh is able to map your data from various format. About data, you must be aware to use compliant geometry types:
It supports data containing these geometries families:
- Point data with Point geometry
- MultiPoint data with MultiPoint geometry
- Line data with LineString and/or MultiLineString geometries
- Polygon data with Polygon and/or MultiPolygon geometries
GeometryCollection data are not supported, so explode it to use it. So the best practice consists to split your input data by geometry type.
And you'll be able, optionally, to style your data thanks to the bokeh arguments : Check bokeh documentation in order to style your data :
- Point / MultiPoint families: bokeh marker style options
- Line family: bokeh multi_line style options
- Polygon family: bokeh multi_polygon style options
Import all required librairies¶
In [1]:
import geopandas as gpd
from bokeh.plotting import output_notebook
from bokeh.plotting import show
from gdf2bokeh import Gdf2Bokeh
output_notebook()
How to ?¶
Prepare input data from geojson¶
In [2]:
layers_to_map = [
{
# contains both Polygon and MultiPolygon features
"title": "[Multi]Polygons layer",
"data": gpd.GeoDataFrame.from_file("tests/fixtures/multipolygons.geojson"),
"from_epsg": 4326,
"fill_color": "orange"
},
{
"title": "Polygons layer",
"data": gpd.GeoDataFrame.from_file("tests/fixtures/polygons.geojson"),
"from_epsg": 4326,
"fill_color": "red",
"line_color": "black"
},
{
"title": "LineString layer",
"data": gpd.GeoDataFrame.from_file("tests/fixtures/linestrings.geojson"),
"from_epsg": 4326,
"color": "color", # we can use the attribute called 'color' containing name color (as usual on bokeh)
"line_width": 4
},
{
# contains both LineString and MultiLineString features
"title": "Multi[LineStrings] layer",
"data": gpd.GeoDataFrame.from_file("tests/fixtures/multilinestrings.geojson"),
"from_epsg": 4326,
"color": "blue",
"line_width": 6
},
{
"title": "MultiPoints layer",
"data": gpd.GeoDataFrame.from_file("tests/fixtures/multipoints.geojson"),
"from_epsg": 4326,
"size": 12,
"fill_color": "yellow",
"line_color": "blue"
},
{
"title": "Points layer",
"data": gpd.GeoDataFrame.from_file("tests/fixtures/points.geojson"),
"from_epsg": 4326,
"size": 6,
"fill_color": "red",
"line_color": "blue"
},
]
Let's go to map our data¶
In [3]:
%%time
map_session = Gdf2Bokeh(
"My beautiful map",
width=800,
height=600,
background_map_name="CARTODBPOSITRON"
)
for layer in layers_to_map:
map_session.add_layer_from_geodataframe(**layer)
map_session.add_layers_on_maps()
show(map_session.figure)
BokehDeprecationWarning: 'circle() method with size value' was deprecated in Bokeh 3.4.0 and will be removed, use 'scatter(size=...) instead' instead. BokehDeprecationWarning: 'circle() method with size value' was deprecated in Bokeh 3.4.0 and will be removed, use 'scatter(size=...) instead' instead.
CPU times: user 151 ms, sys: 75 μs, total: 151 ms Wall time: 150 ms
In [ ]: