首页 > 解决方案 > Python:如何更新 GeoJSONDataSource?

问题描述

Bokeh 现在支持这使得从这里描述GeoJSONDataSource的工作和绘制数据变得更加容易。GeoDataFrame

但是我无法更新。假设我们有两个 shapefileshape1.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)

标签: pythonbokehgeopandas

解决方案


推荐阅读