Closed matteodefelice closed 6 months ago
Deleted last comment as I learned some more after some digging.
Your file has a cached transform:
netcdf test {
dimensions:
band = 1 ;
x = 465 ;
y = 337 ;
variables:
...
int spatial_ref ;
...
spatial_ref:GeoTransform = "3.358333333333316 0.008333333333333349 0.0 53.558333333333344 0.0 -0.008333333333333345" ;
Due to this, the bounds & transform will not update correctly after the sortby
operation because it will pull the resolution from the cached transform.
To address this, you can update the cached transform (or delete it):
df = df.sortby("y")
df.rio.write_transform(df.rio.transform(recalc=True), inplace=True)
And everything works as expected:
df.rio.bounds()
(3.358333333333316, 50.75, 7.233333333333324, 53.558333333333344)
v = geocube.vector.vectorize(df)
v.geometry.total_bounds
[ 3.35833333, 50.75 , 7.23333333, 53.55833333]
test.zip
Today I discovered a strange behaviour when applying
vectorize
on a NetCDF. As expected, the GeoDataFrame and the DataArray have the same extent. However, when I sort they
coordinate of the NetCDF using sortby the extents do not match any more. Here an example using the attachedtest.nc
Output
The extent (the bounds) of the NetCDF is:
while the vectorized GeoDataFrame is:
They should be the same.
Environment Information
Conda environment information (if you installed with conda):
Environment (
conda list
):