部分栅格文件Mosaic拼接失败问题排查求助
栅格瓦片拼接异常问题
问题现象
尝试拼接两个相邻栅格瓦片时出现随机异常:
- 日期"247"的文件拼接正常,结果包含两个瓦片内容
- 日期"248"的文件拼接后仅保留第一个瓦片h12v12,未合并相邻的h13v12
- 该异常在多组文件中随机出现
测试代码
# 加载每日文件路径 files <- c("AOD2022248.h12v12.tif", "AOD2022248.h13v12.tif") files_2 <- c("AOD2022247.h12v12.tif", "AOD2022247.h13v12.tif") # 分别创建栅格栈 test_1 <- stack(files[1]) test_2 <- stack(files[2]) test_3 <- stack(files_2[1]) test_4 <- stack(files_2[2])
尝试的拼接方法及结果
方法1:使用raster::mosaic
- 日期"248"的文件执行报错:
joint <- mosaic(test_1, test_2, fun=mean, filename = "joint.tif", overwrite=TRUE)
报错信息:
Error in v[cells, i] <- as.vector(getValues(x[[i]])) : number of items to replace is not a multiple of replacement length
- 日期"247"的文件执行成功:
joint2 <- mosaic(test_3, test_4, fun=mean, filename = "joint2.tif", overwrite=TRUE)
注:两个日期的瓦片应为并排无重叠,范围本应不同,无法理解报错原因。
方法2:使用gdalUtils::mosaic_rasters
- 无报错信息,但结果异常:
mosaic_rasters(files, dst_dataset= "files.tif") # 输出:[1] "AOD2022248.h12v12.tif" "AOD2022248.h13v12.tif" # NULL mosaic_rasters(files_2, dst_dataset= "files2.tif") # 输出:[1] "AOD2022247.h12v12.tif" "AOD2022247.h13v12.tif" # NULL
- 开启
verbose=TRUE后发现:- 日期"247"的输入文件尺寸为
2400,12000 - 日期"248"的输入文件尺寸为
1200,12000
- 日期"247"的输入文件尺寸为
额外验证
使用compareRaster对比两日同位置瓦片,结果均为TRUE:
> compareRaster(test_1, test_3) [1] TRUE > compareRaster(test_2, test_4) [1] TRUE
疑惑点
既然通过compareRaster验证同位置瓦片属性一致,为何部分日期的文件拼接无法正常工作?
内容的提问来源于stack exchange,提问作者M. Fernanda Valle Seijo
相关产品推荐
相关产品推荐

