Skip to main content

An easy way to map geodataframes on bokeh

Project description

Gdf2Bokeh

An easy way to map your geographic data (from a GeoDataFrame, a DataFrame and a list of dictionaries containing wkt or shapely geometries).

Yeah! Because it's boring to convert shapely geometry to bokeh format each time I need to map something !!

Also, this library let you to build complex Bokeh dashboard: no limitations to use Bokeh mecanisms.

CI codecov

Anaconda-Server Badge Anaconda-Server Badge Anaconda-Server Badge

PyPI version

Check the demo here

How to install it ?

with pip

pip install gdf2bokeh

With Anaconda

conda install -c amauryval gdf2bokeh

How to use it ?

Gdf2Bokeh is able to map your data from various format. About data, you must be aware to use compliant geometry types:

It supports Geo/DataFrame/List of dict/List of geometry containing these 4 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 :

A simple example

from bokeh.plotting import show
import geopandas as gpd
from gdf2bokeh import Gdf2Bokeh

map_session = Gdf2Bokeh()

# add your layer from your data

# Map a points GeoDataFrame. You can see marker style arguments, so we suppose that input_data contains Point geometry
map_session.add_layer_from_geodataframe("layer1", gpd.GeoDataFrame.from_file("your_poins_data.geojson"),
                                        size=6, fill_color="red", line_color="blue")

# Map from a DataFrame. Style parameters are not required
map_session.add_layer_from_dataframe("layer2", gpd.GeoDataFrame.from_file("your_data.json"),
                                     geom_column="geometry", geom_format="shapely")

# Map from a list of dictionnaries
map_session.add_layer_from_dict_list("layer3", 
                                     [
                                         {"geometry": "POINT(0 0)", "col1": "value1"},
                                         {"geometry": "POINT(1 1)", "col1": "value2"}
                                     ],
                                     geom_column="geometry", geom_format="wkt")

# Map from a geometry (shapely, wkt...) list
map_session.add_layer_from_geom_list("layer4", ["Point(0 0)", "Point(5 5)"], geom_format="wkt")

# Let's go to register them on bokeh
map_session.add_layers_on_map()

# Next, the map is displayed
show(map_session.figure)

Here a bokeh basic example. On the terminal, run :

python examples/bokeh_simple_case_example.py

Or you can use the jupyter notebook 'example.ipynb'

An advanced example

Here a bokeh serve example with a slider widget. On the terminal, run :

bokeh serve --show examples/bokeh_serve_example.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gdf2bokeh-3.0.4.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

gdf2bokeh-3.0.4-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page