You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在rioxarray的rio.reproject_match函数中修改重采样方法?

解决rioxarray重投影匹配时的重采样方法问题

可以直接在rio.reproject_match()中修改重采样方法,你遇到的错误是因为两个问题:未导入Resampling枚举类,以及参数名大小写错误。

具体操作步骤:

  • 首先从rasterio中导入Resampling枚举类
  • 调用reproject_match时,使用小写的resampling参数(Python参数遵循蛇形命名规范,不是大写的Resampling)

完整示例代码:

# 导入必要库
import rioxarray
from rasterio.enums import Resampling

# 读取栅格数据
raster_1 = rioxarray.open_rasterio("path/to/raster1.tif")
raster_2 = rioxarray.open_rasterio("path/to/raster2.tif")

# 使用mode重采样进行投影匹配
raster_match = raster_1.rio.reproject_match(raster_2, resampling=Resampling.mode)

# 保存结果
raster_match.rio.to_raster("path/to/matched_raster.tif")

补充说明:

对于土地覆盖这类分类栅格数据,Resampling.mode确实是最优选择——它会在重采样窗口中选择出现频率最高的类别值,能最大程度保留分类数据的语义信息,避免像最近邻可能出现的局部类别偏差。

内容的提问来源于stack exchange,提问作者tazrart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 03:02:34