top of page

Using Bokeh for Geospatial Data Visualization in Python

Writer: Anvita Shrivastava
Anvita Shrivastava
2 days ago
4 min read

The visualization of geospatial data is one of the essential operations in GIS, remote sensing, location intelligence, urban planning, environmental monitoring, and spatial analytics. There are many Python libraries that provide geospatial data manipulation features, but when interactive visualizations, filtering, hover data, and browser-based visualization are required, Bokeh could be used.


Bokeh is an interactive visualization library in Python that allows building plots and other visualizations on the web. Although this library is not a GIS one, Bokeh can be integrated with some geospatial Python libraries like GeoPandas, Shapely, and pyproj.


Bokeh for Geospatial Data Visualization
Bokeh for Geospatial Data Visualization

What Is Bokeh?


Bokeh is an open-source Python package used for developing interactive data visualizations in a browser environment. It offers the following capabilities:


  • Interactive maps and plots

  • Pan and zoom operations

  • Tooltip information on hover

  • Linked selection functionality

  • Dynamic filtering

  • Web-based dashboards

  • Updating and streaming of data

  • Visualization of GeoJSON

  • Embedding JavaScript through BokehJS


Unlike static plotting packages, Bokeh is built specifically for interactive visualization purposes. In this way, it becomes more suitable for cases where one wants to explore large amounts of data rather than create a static map.


When it comes to geospatial analysis, Bokeh is capable of working with geographic coordinates and GeoJSON objects.


Why Use Bokeh for Geospatial Visualization?


There are powerful geographic visualization tools in conventional GIS software. In practice, however, sometimes it is necessary to integrate interactive geospatial visualizations in applications and websites in Python.


This is where Bokeh is helpful since it allows developing several interactive elements without creating an entire JavaScript visualization application.


Advantages include:


Interactive visualization: The ability to pan, zoom, and explore the geographic features.


Python workflow: Preparation of the geospatial data in Python libraries and visualization with Bokeh.


Visualization for browser: It is possible to visualize the maps in web browsers.


Interactively showing attributes: Information on the geographic feature, including its name, category, population, measurement, and so forth.


Representation of geometries: Polygon, line, and point geometries may be depicted via GeoJSON.


Integration in dashboard: Bokeh makes it possible to develop interactive analytical applications with Bokeh Server.


Installing Bokeh and Geospatial Libraries


Install the required packages with pip:

pip install bokeh geopandas shapely pyproj pandas

You can verify the Bokeh installation with:

import bokeh

print(bokeh.__version__)

For a simple geospatial workflow, you can import the libraries as follows:

import geopandas as gpd
import pandas as pd

from bokeh. plotting import figure, show
from bokeh. models import GeoJSONDataSource, HoverTool

Understanding Coordinates in Bokeh


One of the most important considerations when creating a geospatial visualization is the coordinate reference system (CRS).

Geospatial datasets may use geographic coordinates such as:

EPSG:4326

which represents longitude and latitude, or projected coordinate systems such as Web Mercator:

EPSG:3857

For many web mapping workflows, coordinates need to be transformed into Web Mercator before visualization.

For example:

gdf = gdf.to_crs(epsg=3857)

You can check the CRS of a GeoDataFrame with:

print(gdf.crs)

Correct CRS handling is essential because mixing longitude/latitude coordinates with projected coordinates can produce incorrectly positioned geometries.


Creating a Simple Point Map with Bokeh


Suppose you have a dataset containing geographic locations:

import pandas as pd

data = pd.DataFrame({
    "name": ["Location A", "Location B", "Location C"],
    "longitude": [-73.9857, -74.0060, -73.9352],
    "latitude": [40.7484, 40.7128, 40.7306]
})

Create a Bokeh figure:

from bokeh.plotting import figure, show

p = figure(
    title="Geospatial Point Visualization",
    x_axis_type="mercator",
    y_axis_type="mercator",
    width=900,
    height=600
)

p.scatter(
    x=data["longitude"],
    y=data["latitude"],
    size=10
)

show(p)

However, longitude and latitude should generally be converted to Web Mercator coordinates before using a Mercator-based plot.


Visualizing GeoJSON with Bokeh


One of Bokeh's most useful features for geospatial applications is its GeoJSONDataSource.

Suppose you have a GeoDataFrame containing polygon features:

import geopandas as gpd

gdf = gpd.read_file("districts.geojson")

Convert the dataset to Web Mercator:

gdf = gdf.to_crs(epsg=3857)

Then convert it to GeoJSON:

geojson = gdf.to_json()

Create a Bokeh GeoJSON data source:

from bokeh. models import GeoJSONDataSource

source = GeoJSONDataSource(geojson=geojson)

You can then render the polygons:

p = figure(
    title="Interactive Geospatial Polygons",
    x_axis_type="mercator",
    y_axis_type="mercator",
    width=900,
    height=600
)

p.patches(
    xs="xs",
    ys="ys",
    source=source
)

show(p)

This approach can be used for administrative boundaries, parcels, districts, watersheds, land-use zones, and other polygon-based spatial datasets.


Using GeoPandas with Bokeh


A typical workflow combines GeoPandas for spatial processing and Bokeh for visualization.

import geopandas as gpd
from bokeh. plotting import figure, show
from bokeh. models import GeoJSONDataSource

gdf = gpd.read_file("roads.geojson")

gdf = gdf.to_crs(epsg=3857)

source = GeoJSONDataSource(
    geojson=gdf.to_json()
)

p = figure(
    title="Interactive Road Network",
    x_axis_type="mercator",
    y_axis_type="mercator",
    width=1000,
    height=700
)

p.multi_line(
    xs="xs",
    ys="ys",
    source=source
)

show(p)

This workflow separates responsibilities effectively:


GeoPandas → spatial data processing

pyproj → CRS transformation

Bokeh → interactive visualization


Bokeh for Geospatial Dashboards


Bokeh becomes particularly powerful when combined with multiple interactive components.

A GIS dashboard might include:

------------------------------------------------
|             Interactive Map                  |
|                                              |
|       Spatial Features + Basemap             |
|                                              |
------------------------------------------------
| Filter | Statistics | Feature Information    |
------------------------------------------------

For example, a drone mapping dashboard could display:

  • Flight boundaries

  • Ground control points

  • Orthomosaic footprints

  • Inspection locations

  • Detected objects

  • Elevation measurements

  • Survey statistics


Users could select a flight, filter features, and inspect individual observations interactively.

Bokeh Server can be used when the application requires Python-driven callbacks and dynamic server-side interaction.


Bokeh offers an effective interactive geospatial data visualization toolkit based on Python. Despite not being a full-fledged GIS environment, the tool, with its interactivity, support for GeoJSON, hover tools, widgets, and dashboards, becomes useful in developing web applications that are geospatial by nature.


In particular, Bokeh in combination with GeoPandas (for working with spatial data) and pyproj (for handling different coordinate reference systems) allows developers to create applications in fields such as GIS, drone mapping, remote sensing, environmental monitoring, transport, agriculture, and location intelligence.


In case of large-scale geospatial data analysis workflows, the use of Bokeh can be extended by adding GeoParquet, PostGIS, Rasterio, Shapely, GDAL, and cloud-based spatial analytics platforms to the Python geospatial toolkit.


In general, Bokeh should be considered the visual layer of the application, which works with specialized geospatial libraries for preparing the data for visualization.


To learn more about Bokeh and its geospatial capabilities, click here.


For more information or any questions regarding the LizardTech suite of products, please don't hesitate to contact us at:



USA (HQ): (720) 702–4849


(A GeoWGS84 Corp Company)



Comments


bottom of page