Geospatial 将rioxarray剪裁到shapefile时发生CRS错误
我试图将rioxarray数据集剪裁到shapefile,但出现以下错误:Geospatial 将rioxarray剪裁到shapefile时发生CRS错误,geospatial,clip,Geospatial,Clip,我试图将rioxarray数据集剪裁到shapefile,但出现以下错误: > data_clipped = data.rio.clip(shape.geometry.apply(mapping)) MissingCRS: CRS not found. Please set the CRS with 'set_crs()' or 'write_crs()'. Data variable: precip 这个错误看起来很简单,但我无法确定需要设置哪些CRS。dataset和shapefil
> data_clipped = data.rio.clip(shape.geometry.apply(mapping))
MissingCRS: CRS not found. Please set the CRS with 'set_crs()' or 'write_crs()'. Data variable: precip
这个错误看起来很简单,但我无法确定需要设置哪些CRS。dataset和shapefile都具有rio可以找到的CRS值:
> print(data.rio.crs)
EPSG:4326
> print(shape.crs)
epsg:4326
数据集中名为“precip”的dataarray没有CRS,但似乎也没有响应set_CRS()命令:
我错过了什么
作为参考,-这显示了set_crs()处理数据数组,与我使用data.precip的经验不同 我的数据,以防我有不寻常的事情:
> print(data)
<xarray.Dataset>
Dimensions: (x: 541, y: 411)
Coordinates:
* y (y) float64 75.0 74.9 74.8 74.7 74.6 ... 34.3 34.2 34.1 34.0
* x (x) float64 -12.0 -11.9 -11.8 -11.7 ... 41.7 41.8 41.9 42.0
time object 2020-01-01 00:00:00
spatial_ref int64 0
Data variables:
precip (y, x) float64 nan nan nan ... 1.388e-17 1.388e-17 1.388e-17
Attributes:
Conventions: CF-1.6
history: 2021-01-05 01:36:52 GMT by grib_to_netcdf-2.16.0: /opt/ecmw...
如果在与剪辑操作相同的命令中使用set_crs(),则可以解决此问题:
data_clipped = data.precip.rio.set_crs('WGS84').rio.clip(shape.geometry.apply(mapping))
这可能意味着
data.precip.rio.set_crs()
不是就地操作,因此您可以执行data=data.precip.rio.set_crs()
,并在另一行执行data.rio.clip()
。
> print(shape)
ID name orgn_name geometry
0 Albania Shqipëria MULTIPOLYGON (((19.50115 40.96230, 19.50563 40...
1 Andorra Andorra POLYGON ((1.43992 42.60649, 1.45041 42.60596, ...
2 Austria Österreich POLYGON ((16.00000 48.77775, 16.00000 48.78252...
data_clipped = data.precip.rio.set_crs('WGS84').rio.clip(shape.geometry.apply(mapping))