Python:如何更新GeoJSONDataSource?

时间:2019-05-30 12:26:16

标签: python bokeh geopandas

如今,Bokeh支持GeoJSONDataSource,使here所述的GeoDataFrame数据的绘制和绘制变得更加容易。

但是我无法更新。假设我们有两个shapefile shape1.shpshape2.shp。这是我在做的,但是我无法更新形状

import geopandas as gpd
from bokeh.plotting import save, figure
from bokeh.models import GeoJSONDataSource
from bokeh.models import Select
from bokeh.io import curdoc
from bokeh.layouts import row, column, widgetbox,layout, gridplot

f1  = gpd.read_file('shape1.shp')
f1g  = GeoJSONDataSource(geojson=f1.to_json())

f2  = gpd.read_file('shape2.shp')
f2g  = GeoJSONDataSource(geojson=f2.to_json())

select =  Select(title="Shape",  options = ['F1','F2'], value, ='F1')
geo_source1 = f1g ### first shape
p = figure(plot_width=600,plot_height=500)
p.patches('xs', 'ys', source = geo_source1, fill_color='white')

def update_plot(attrname, old, new):
    if select.value == 'F2':
        geo_source1.geojson = f1g.geojson   #first shape
    if select.value == 'F2':
        geo_source1.geojson = f2g.geojson   #second shape

select.on_change('value', update_plot)

controls = widgetbox(select1)
first_row = row(controls,p)
curdoc().add_root(first_row)

0 个答案:

没有答案