Box & Lasso select tool with patches

I am failing to implement box_select behaviour when using geopandas data. The tool is shown and can be chosen, however nothing happens upon selection made (with shift key held or without). I’ve now tried this on two seperate shapefiles and got the same problem.
Tap select seems to work fine and so does box zoom.

any ideas?

UPDATE: found this post from 2015-6, not sure if it has been implemented since?

code below, example data from this link. Thanks

from pathlib import Path
import geopandas as gpd
import json
import os

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

from bokeh.models import BoxSelectTool

#notebook environment
from import show, output_notebook

dataFolder = Path(os.getcwd()).parent
dataFolder = os.path.join(dataFolder, "data")
shapefile = os.path.join (str(dataFolder) + '/USA Counties 20m/cb_2017_us_county_20m_with_cZone_USAF_coordinates_elevations_timezones.shp')

#Read shapefile using Geopandas
gdf = gpd.read_file(shapefile)

print ('SHP file loaded successfully')

#Read data to json.
json_raw = json.loads(gdf.to_json())

#Convert to String like object.
json_data = json.dumps(json_raw)

#Input GeoJSON source that contains features for plotting.
geosource = GeoJSONDataSource(geojson = json_data)

p = figure(title = 'SF Landuse Map', plot_height = 450 , plot_width = 750, toolbar_location = "below")

box_select = BoxSelectTool()

p.patches('xs','ys', source = geosource, line_color = 'black', line_width = 0.01, fill_alpha = 1) 

As of Bokeh 1.2 the Patches glyph only supports “point” hit-testing, so only the TapTool will work for selections. Supporting other tools would mean:

  • First, defining exactly what the behavior should be, i.e. what counts as a “hit” for purposes of selection? Does any intersection with a box/lasso count? Does the entire patch have to be fully enclosed? Or maybe if the box/lasso contains the centroid? It doesn’t make sense to implement anything until this question is resolved.

  • The _hit_rect and/or _hit_poly need to be implemented on Patches in patches.ts. As soon as that is done, everything else will just start to work.

I’d encourage you to chime in on the existing GitHub issue to discuss it futher, and (hopefully, if you are able) help out to get it added sooner than later.