如何解决将 rioxarray 剪切到 shapefile 时出现 CRS 错误
我正在尝试将 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。数据集和 shapefile 都有 rio 可以找到的 CRS 值:
> print(data.rio.crs)
EPSG:4326
> print(shape.crs)
epsg:4326
数据集中的数据数组,称为“precip”,没有 CRS,但它似乎也没有响应 set_crs() 命令:
> print(data.precip.rio.crs)
None
> data.precip.rio.set_crs(data.rio.crs)
> print(data.precip.rio.crs)
None
我在这里遗漏了什么?
作为参考,rioxarray set_crs() documentation - 这显示了 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...
> 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...
解决方法
如果 set_crs() 与剪辑操作在同一命令中使用,则此问题已解决:
data_clipped = data.precip.rio.set_crs('WGS84').rio.clip(shape.geometry.apply(mapping))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。