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

如何在R terra中裁剪、投影并合并跨antimeridian的栅格数据?

跨日界线栅格投影合并的分辨率差异与数据缺口问题

问题背景

我从EPSG:4326的全球经纬度栅格中裁剪跨日界线的区域,为减少计算量,选择分别裁剪日界线两侧的子区域,投影到斐济本地等面积坐标系后再合并。但遇到两个问题:

  • 投影后两个子区域的栅格分辨率略有不同
  • 即使通过resample统一分辨率,合并结果在日界线附近仍存在数据缺口

原因分析

分辨率差异的原因

使用terra::project()且未指定目标分辨率时,程序会根据原栅格分辨率、原区域地理范围,以及目标投影的坐标范围自动计算输出分辨率。由于两个裁剪区域(176-180°E、-180--177°W)的经纬度范围不同,投影到本地坐标系后的地理范围宽高比例存在细微差异,导致自动计算出的分辨率出现小幅偏差。

数据缺口的原因

  1. 栅格对齐不一致:仅通过resample()统一分辨率,无法保证两个栅格的行列起始坐标(栅格对齐方式)完全匹配,重叠区域的栅格单元无法对应,合并后出现空隙。
  2. 边缘采样缺失:原裁剪区域的边缘在投影转换时,可能因坐标精度问题导致边缘栅格单元未被正确填充,resample过程也无法补全这些缺失值。

解决方案

核心思路:投影阶段统一栅格模板

提前创建覆盖两个子区域总范围的目标栅格模板,将两个半区都投影到该模板上,确保分辨率、行列数、坐标对齐完全一致,从根源避免问题。

修正后的代码

library(terra)
library(geodata)

# 斐济本地等面积投影参数
fiji_crs <- "+proj=laea +lon_0=-181.8896484 +lat_0=-17.73775 +datum=WGS84 +units=m +no_defs"

# 获取温度数据(取第一个栅格)
fiji_temp <- bio_oracle(path=tempdir(), "Temperature", "Mean", benthic=FALSE, time="Present")[[1]]

# 分日界线两侧裁剪区域
fiji_temp_lhs <- crop(fiji_temp, ext(176, 180, -21, -12))
fiji_temp_rhs <- crop(fiji_temp, ext(-180, -177, -21, -12))

# 临时投影获取合并后的总范围
temp_lhs_proj <- project(fiji_temp_lhs, fiji_crs)
temp_rhs_proj <- project(fiji_temp_rhs, fiji_crs)
total_ext <- ext(c(xmin(temp_lhs_proj), xmax(temp_rhs_proj), ymin(temp_rhs_proj), ymax(temp_lhs_proj)))

# 创建统一的目标栅格模板(使用左侧栅格的分辨率)
target_rast <- rast(total_ext, res = res(temp_lhs_proj), crs = fiji_crs)

# 将两个半区投影到统一模板
fiji_temp_lhs_proj <- project(fiji_temp_lhs, target_rast)
fiji_temp_rhs_proj <- project(fiji_temp_rhs, target_rast)

# 合并栅格
merged_rast <- merge(sprc(fiji_temp_lhs_proj, fiji_temp_rhs_proj))
plot(merged_rast)

额外优化建议

  • 调整裁剪范围增加重叠:将两侧裁剪范围调整为175-180°E和-180--176°W,让投影后的区域有更多重叠,进一步避免边缘缺口。
  • 指定插值方法:投影时可通过method参数指定插值方式(如method="bilinear"),提升边缘区域的数值精度。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 17:05:55