Deltares / xugrid

Xarray and unstructured grids
https://deltares.github.io/xugrid/
MIT License
61 stars 8 forks source link

BUG: ugriddatasetaccessor.to_geodataframe #142

Closed hboisgon closed 1 year ago

hboisgon commented 1 year ago

I tried using the to_geodataframe method for UgridDataset but found two issues:

The lines in question:

https://github.com/Deltares/xugrid/blob/b6c4fb5570af34a264783e709e948114255a6a71/xugrid/core/dataset_accessor.py#L394-L403

An idea of implementation:

gdf = gpd.GeoDataFrame(
    index=grid.to_dataset()[dim].values.astype(str),
    data=ds[variables].to_dataframe(dim_order=dim_order) if len(variables)>0 else None,
    geometry=grid.to_shapely(dim),
    crs = grid.crs,
)
Huite commented 1 year ago

Hi @hboisgon,

The CRS thing has an issue for itself with #138. Allowing to create a GeoDataFrame with only geometry seems reasonable.