我正在尝试使用geoviews地图图块覆盖其基础数据集可能会更改的矢量要素。以下是一些说明问题的示例代码,当我更改基础矢量数据集时,该问题无法正确呈现。此示例来自here,并且与我最近发布的another question有关。
import panel as pn
import numpy as np
import param as pm
import holoviews as hv
import geoviews as gv
import geoviews.tile_sources as gts
from holoviews.operation.datashader import rasterize
from collections import OrderedDict as odict
import geopandas as gpd
renderer = hv.renderer('bokeh')
pn.extension()
#Define Example Datasets
vect_dat = {'v1':gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')),'v2':gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))}
vect_dat2 = {'v1':gv.Polygons(gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')),vdims='continent', label='id').opts(tools=['hover'],line_color='k',fill_alpha=0),
'v2':gv.Points(gpd.read_file(gpd.datasets.get_path('naturalearth_cities')),vdims='name', label='id').opts(tools=['hover'],line_color='k',fill_alpha=0)}
maps = ['EsriImagery','EsriNatGeo', 'EsriTerrain', 'OSM']
bases = odict([(name, gts.tile_sources[name].relabel(name)) for name in maps])
gopts = hv.opts.WMTS(responsive=True, xaxis=None, yaxis=None, bgcolor='white', show_grid=False)
class sel_vect():
def v1():
return gv.Polygons(vect_dat['v1'],vdims='continent', label='id').opts(tools=['hover'],line_color='k',fill_alpha=0)
def v2():
return gv.Points(vect_dat['v2'],vdims='name', label='id').opts(tools=['hover'],line_color='k',fill_alpha=0)
#Dashboard
class Explorer_Test(pm.Parameterized):
basemap = pm.Selector(bases)
spat = pm.Selector(list(vect_dat2.keys()))
map_opacity = pm.Magnitude(1.00)
@pm.depends('basemap','map_opacity')
def tiles(self):
return self.basemap.opts(gopts).opts(alpha=self.map_opacity)
@pm.depends('spat')
def elem_spat(self):
return getattr(sel_vect,self.spat)()
def viewable(self,**kwargs):
return hv.DynamicMap(self.elem_spat)*hv.DynamicMap(self.tiles)
explorer_test = Explorer_Test(name="")
panel = pn.Row(pn.Param(explorer_test.param, expand_button=False),explorer_test.viewable())
panel.servable()
在此示例中,如果我将矢量数据集从“ v1”更改为“ v2”,则面板将无法渲染。
谢谢。