Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: ugriddatasetaccessor.to_geodataframe #142

Closed
hboisgon opened this issue Aug 8, 2023 · 1 comment
Closed

BUG: ugriddatasetaccessor.to_geodataframe #142

hboisgon opened this issue Aug 8, 2023 · 1 comment

Comments

@hboisgon
Copy link

hboisgon commented Aug 8, 2023

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

  • sometimes, the Dataset can contain no variables yet (eg uds = Ugrid2d.to_datatset()) and this is not allowed
  • the crs is not passed to the geodataframe and is lost in the conversion.

The lines in question:

variables = [var for var in ds.data_vars if dim in ds[var].dims]
# TODO deal with time-dependent data, etc.
# Basically requires checking which variables are static, which aren't.
# For non-static, requires repeating all geometries.
# Call reset_index on multi-index to generate them as regular columns.
gdfs.append(
gpd.GeoDataFrame(
data=ds[variables].to_dataframe(dim_order=dim_order),
geometry=grid.to_shapely(dim),
)

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
Copy link
Collaborator

Huite commented Aug 8, 2023

Hi @hboisgon,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants