diff --git a/hvplot/converter.py b/hvplot/converter.py index 00e31fe12..b1b03f80d 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -59,6 +59,7 @@ is_cudf, is_streamz, is_ibis, + is_xvec, is_xarray, is_xarray_dataarray, process_crs, @@ -1048,6 +1049,22 @@ def _process_data( if col is not None: grid.append(col) streaming = False + + if is_xvec(data): + import xvec # noqa: F401 + + geom_coords = list(data.xvec.geom_coords) + if len(geom_coords) > 1: + param.main.param.warning( + f'Only the first geometry coord will be rendered: {geom_coords[0]!r}. The ' + f"others are 'flattened' in groupby: {geom_coords[1:]}" + ) + data = data.drop_vars(geom_coords[1:]) + if groupby is None: + groupby = [dim for dim in data.dims if dim != geom_coords[0]] + data = data.xvec.to_geodataframe() + self.source_data = data + if is_geodataframe(data): datatype = 'geopandas' if hasattr(data, 'geom_type') else 'spatialpandas' self.data = data diff --git a/hvplot/util.py b/hvplot/util.py index 75f1df016..9eeb4187c 100644 --- a/hvplot/util.py +++ b/hvplot/util.py @@ -430,6 +430,14 @@ def is_streamz(data): return sdf and isinstance(data, (sdf.DataFrame, sdf.Series, sdf.DataFrames, sdf.Seriess)) +def is_xvec(data): + if not hasattr(data, 'xvec'): + return False + import xvec # noqa + + return len(data.xvec.geom_coords) > 0 + + def is_xarray(data): if not check_library(data, 'xarray'): return False @@ -482,7 +490,18 @@ def is_geodataframe(data): def process_xarray( - data, x, y, by, groupby, use_dask, persist, gridded, label, value_label, other_dims, kind=None + data, + x, + y, + by, + groupby, + use_dask, + persist, + gridded, + label, + value_label, + other_dims, + kind=None, ): import xarray as xr @@ -509,6 +528,7 @@ def process_xarray( data_vars = list(dataset.data_vars) ignore = (by or []) + (groupby or []) + dims = [c for c in dataset.coords if dataset[c].shape != () and c not in ignore][::-1] index_dims = [d for d in dims if d in dataset.indexes] @@ -565,6 +585,7 @@ def process_xarray( if groupby is None: groupby = [c for c in leftover_dims if c not in (by or [])] + return data, x, y, by, groupby