Closed xldeltares closed 1 year ago
The inconsistency between geodataframe <-> ugrid shouldn't happen because it's using the same python object. This should be easy to fix.
Going from and to netCDF is more complicated, since there are many ways in how people write CRS information into their netCDF files. I think the CF conventions prescribe writing a grid mapping variable, but I'm pretty sure I have seen other files where there's just an "epsg_code" floating around somewhere.
At any rate, a reasonable fraction seems to contain a grid mapping variable, so we should add some logic to parse and write it. It could get a little tricky since it wouldn't be unreasonable to have the thing refer to ordinary x and y variables of a structured grid... but in general, it seems like a reasonable assumption that if you want to create UgridDataset out of something that xy plane is represented by an unstructured grid, and that the grid mapping refers to that part.
With regards to netCDF, I'm closing this in favour of #42, which has a bit more background.
Description crs is not consistent in the following:
How to reproduce Given:
When creating a Ugrid1d from geodataframe, crs from the geodataframe is not used in Ugrid1d. crs needs to be set again in order for crs to be correctly assigned to Ugrid1d.
Given that now the Ugrid1d does have crs, when creating a UgridDataset from the ugrid1d, the crs is not passed on again. crs needs to be set again in order for crs to be correctly assigned.
Now that I do have crs, when calling to_geodataframe(), the crs is again not passed on. crs needs to be set again in order for crs to be correctly assigned.
Finally, if I write the uds with correct crs to a netcdf file then read it back using
open_dataset
the crs is lost again. crs needs to be set again in order for crs to be correctly assigned.Expected behavior The crs is harmonized among all objects. Otherwise, the user needs to set crs repeatedly.