How do map objects work and where can we get / create them?

I’m trying to figure out maps and am toying with the code from this example.

On closer inspection it seems this is a patches figure, and the figure is using a giant list of coordinates to outline the shapes of counties. Cool! Is this the best / only way create maps in Bokeh?

Let’s say I want to make a map of suburbs in some country and depict some data with different colors / tooltips. What’s a good way to do this? Recommendations on how to get geo data?

OK I’ve made progress trying to adapt from this SO example. It explains how GeoJSON is kinda the standard for JavaScript and seems to be the easiest way to do maps with Bokeh.

Here’s what I’ve got now cutting out unnecessary detail:

from bokeh.io import show
from bokeh.models import (
    GeoJSONDataSource)
from bokeh.plotting import figure

with open(r'aus.geo.json', 'r') as f:
    geo_source = GeoJSONDataSource(geojson=f.read())

TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"

p = figure(tools=TOOLS, x_axis_location=None, y_axis_location=None)
p.grid.grid_line_color = None

p.patches('xs', 'ys', fill_color='orange', source=geo_source)

show(p)

This seems to be a good site to download GeoJSON files from, and it’s where I downloaded a map of Australia, renamed to aus.geo.json.

Normal mapping with the likes of GIS seems to be done with .shp files, and there’s an abundance of great .shp files out there. But I’m still trying to figure out how to turn .shp into .json, or if that’s even possible.

Would also appreciate guidance on how to set output to correct aspect ratio and set map projections.

GeoJSON support in Bokeh is fairly limited at present. Only points and polygons-without-holes are supported IIRC. There is an example how to load a GeoJSON file here:

bokeh/geojson_points.py at branch-2.3 · bokeh/bokeh · GitHub

If you have more extensive needs, you might consider a more specialized project like GeoViews (which can also generate Bokeh output, just from a higher level).

Oh, right. Is there anything I can do to help develop maps in Bokeh? Or are other things taking priority atm?

I like the look of GeoViews but I’m after something more customizable. Suggestions for other tools? Are there any other Python based tools or would it be best to try the likes of D3.js?

cc @Philipp_Rudiger in case he can answer questions about GeoViews customization

Oh, right. Is there anything I can do to help develop maps in Bokeh? Or are other things taking priority atm?

There’s a mix of reasons, e.g. when Geo support was first added, some glyphs like MulitPloygons which can draw more general (disconnected) shapes did not yet exist. No one has yet gone back to update the GeoJSON bits of Bokeh to make use of those new glyphs. That might be fairy simple, at least just for drawing. I think there are still TBD things to do with hit-testing and other interactions on MulitPloygons so that might more difficult, and have to be left incomplete to start.

There’s also just not much GIS depth on the core team. So there is some amount of reticence, e.g. on my part, to spend time on Geo things because without experience/real use-cases to inform the development, there is a risk of sinking time into building a wrong solution.

Then, as you mention, there are always competing priorities. FWIW we don’t actually seem to get many requests about Geo / GIS things, so they just don’t get as much attention.

If you have GIS background / strong opinions and some JS experience, then we’d certainly be grateful for any help moving that part of Bokeh forward.

Yeah, I don’t think I’ve got skills that’d be helpful, but I try to help where I can. Only basic experience with QGIS, and I’m a JS beginner at best. I’m only a nerd, not a programmer :nerd_face:

there are always competing priorities. FWIW we don’t actually seem to get many requests about Geo / GIS things, so they just don’t get as much attention.

Totally agree with you, it’s silly to prioritize developing unwanted things. You’d know better than me, but maybe there’d be more interest if people got a taste for it? IMO often people don’t know what they want until they see it and some of the interactive maps built with D3 are jaw dropping.

Also, QGIS has some Python functionality I don’t understand. Maybe that could be leveraged somehow?

@tvkyq Since all the actual rendering and most of the work in general takes place in JavaScript in the browser, Python l libraries are not usually especially useful for integration targets. This is especially true if the Python tool generates visuals or graphics from Python, there’s just nothing much for Bokeh to do with that since it’s not in the browser. Where we integrate with Python tools is typically just around data preparation, e.g adapting data structures from Pandas or networkx.