corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
504 stars 80 forks source link

rioxarray can't clip nc files by the samll bound files? #716

Closed CGL5230 closed 6 months ago

CGL5230 commented 7 months ago
for idx, row in gdf.iterrows():
    name = row['NAME']  
    geometry = row['geometry']  
    print(row['NAME'])
    ERA5_AP_ds = ERA5_AP.rio.clip([geometry],all_touched=True)
    AWI_CM_ssp126_AP_ds = AWI_CM_ssp126_AP.rio.clip([geometry],all_touched=True)

Problem description

Hi,all! I try to clip the netcdf files with the shape files. It is worth noting that this shp file contains a number of sub-regions within it. The code above is cropping all the sub-regions. But again, this results in the boundaries of the crop becoming very small. As a result, the error was report:“NoDataInBounds: No data found in bounds.”
I think the small boundary will the core of problem and related to this post. It is Archipiélago de Revillagigedo(location) and the resolution of cmip6 is 0.9 degree.

image

Expected Output

I set the all_touched=True that means I'll get at least one like grid point value.

Environment Information

Installation method

pip

CGL5230 commented 7 months ago

As you can see the geometry touched the grid. But still report "No data in bounds" image

CGL5230 commented 7 months ago

I meet the same error again. I think the point is cropped_ds.coords[self.x_dim].size < 1 or cropped_ds.coords[self.y_dim].size < 1. You can see the boundary for another shape file. Is there anyway to return the touched cells for rio.clip method? By the way, can I use the clip.box to clip? How can I pass my shape file boundary to this? image

I meet a werid problem... The length of boundary is more than cropped_ds.coords[self.x_dim].size < 1 or cropped_ds.coords[self.y_dim].size < 1. But still report "No data in Bounds" error. image

CGL5230 commented 6 months ago

I think the reason is the longitude of the dataset. It's range is 0-360 degree. So I minus 180 with the lon parameter. It work!