I’ve tried using both gv.Shape.from_records()
and hvplot.pandas
and both seem to halt interactivity after I launch a panel app. Is there a third way that I’m missing?
Here’s some sample code of mine:
import panel as pn
import xarray as xr
import hvplot.xarray
import hvplot.pandas
shp = gpd.read_file("/Users/james/Downloads/cb_2018_us_county_500k/cb_2018_us_county_500k.shp")
ds = xr.open_dataset("http://basin.ceoe.udel.edu/thredds/dodsC/DEOSRefET.nc")
df = ds.refET[0]
df.hvplot.quadmesh(width=500, height=1000, x='longitude', y='latitude', project=True, geo=True,
rasterize=True, dynamic=False) * shp.hvplot(geo=True, color=None)
I’m trying to use panel to visualize this dataset but figured it would be best to start out with the general holoviews code I’m basing the panel code off of. I can attach my full code if necessary.
I’ve found through trial and error that the most efficient way to overlay a shapefile onto a hvplot.xarray quadmesh plot is via cartopy
and geoviews
. An important note that was helpful was clipping the shapefile to a much smaller domain that fit my data before overlaying it on the image. I did this using GDAL’s ogr2ogr
. Once the file was clipped, I used cartopy.io.shapereader
to load in a shapefile and then use geoviews.Shape.from_records()
. Once it’s a geoviews.Shape
object, I convert it to a geoviews.Polygon
object for overlay. Below is an example:
import panel as pn
import xarray as xr
import hvplot.xarray
import hvplot.pandas
import cartopy.io.shapereader as shpreader
state_lines = shpreader.Reader("/Users/James/Downloads/cb_2018_us_state_500k/" + 'cb_2018_us_state_500clipped.shp')
state_lines = gv.Shape.from_records(state_lines.records())
shp = gv.Polygons(state_lines).opts('Polygons', line_color='black',fill_color=None)
ds = xr.open_dataset("http://basin.ceoe.udel.edu/thredds/dodsC/DEOSRefET.nc")
df = ds.refET[0]
df.hvplot.quadmesh(width=500, height=1000, x='longitude', y='latitude', project=True, geo=True,
rasterize=True, dynamic=False) * shp
Sorry I never responded here, the most efficient approach should definitely be what you tried first and if that doesn’t work we should track down the reason so an issue would be good.