Update data from gv.Polygons

To take advantage of more optimized updates you will want to use a HoloViews DynamicMap which returns the updated data, as an example here we assign some random values to a geopandas dataframe in the callback depending on the value of a widget:

import geopandas as gpd
import geoviews as gv
import numpy as np
import cartopy.crs as ccrs

gv.extension('bokeh')

polygons = gpd.read_file(gpd.datasets.get_path('nybb'))
polygons = polygons.to_crs(epsg=3857)


def update_poly(some_value):
    polygons['value'] = np.random.rand(5) * some_value
    return gv.Polygons(polygons, vdims=['value'], crs=ccrs.GOOGLE_MERCATOR).opts(clim=(0, 10))

widget = pn.widgets.FloatSlider(name='Scale Factor', start=1, end=10)

pn.Row(
    widget,
    gv.tile_sources.Wikipedia() * gv.DynamicMap(pn.bind(update_poly, widget))
)

update_scale_factor

1 Like