Как обновить выделение на Bokeh с shapefiles - PullRequest
0 голосов
/ 20 мая 2019

Я пытаюсь выбрать точки в определенном регионе, используя bokeh, и я использую функцию selectBoundary, как описано ниже. Выбор по зданиям, т. Е. select, работает, а выбор по городам - ​​нет, т. Е. select1, и я не знаю, почему

import geopandas as gpd
from geopandas.tools import sjoin

s = schools.copy()  ## schools point (geopandas dataframe)
h = hf.copy()       ## hospitals points (geopandas dataframe)
dpt = cities.copy() ## cities (geopandas dataframe)


def selectBoundary(dptSelected):
    if dptSelected == 'City1':
        dptTmp = dpt[dpt.index==0]
        s = sjoin(schools, dpt)
        h = sjoin(hf, dpt)
    else:
        s = schools.copy()
        h = hf.copy()
    return s,h

def update_plot(attrname, old, new):
    s,h = selectBoundary(select1.value)
    if select.value == 'Schools':
        point0=dict(
            x=list(s['x'].values),
            y=list(s['y'].values),
        )
        newSource = point0  
    if select.value == 'Hospitals':
        point1=dict(
            x=list(h['x'].values),
            y=list(h['y'].values),
        )
        newSource = point1  
    source_point.data  =  newSource

Есть ли сюжет

point0=dict(
    x=list(s['x'].values),
    y=list(s['y'].values),
)

point1=dict(
    x=list(h['x'].values),
    y=list(h['y'].values),
)
source_point = ColumnDataSource(data = point0)

p = figure(plot_width=800, 
           tooltips=[("(Long, Lat)", "($x, $y)")])

p.hover.point_policy = "follow_mouse"

p.circle('x', 'y', size=1, 
         source = source_point, 
         color="black")

## Selection
select  =  Select(title="Buildings",  options=['Schools', 'Hospitals' ])
## Selection

select1 =  Select(title="Departments",  options = ['None', 'City1'])


## Controls
controls = widgetbox(select, select1)
select.on_change('value', update_plot)
select1.on_change('value', update_plot)
layout = column(row(controls), p)
curdoc().add_root(layout)
...