使用 terra 创建栅格图块马赛克时如何避免内存问题?

How to avoid memory issues when creating a mosaic of raster tiles using terra?

我有一个包含 375 个栅格图块的列表,我想将它们拼接成一个栅格:

filelist_lc <- list.files("Northern_Land_Cover_2000/")
lc_2000_tiles <- lapply(filelist_lc, rast)

> lc_2000_tiles[[1]]
class       : SpatRaster 
dimensions  : 4962, 5049, 1  (nrow, ncol, nlyr)
resolution  : 30, 30  (x, y)
extent      : 1614258, 1765728, 8094905, 8243765  (xmin, xmax, ymin, ymax)
coord. ref. : LCC         E008 
source      : 014M.tif 
name        : 014M 

lc_2000_tiles[[2]]
class       : SpatRaster 
dimensions  : 4791, 4747, 1  (nrow, ncol, nlyr)
resolution  : 30, 30  (x, y)
extent      : 1462288, 1604698, 8381835, 8525565  (xmin, xmax, ymin, ymax)
coord. ref. : LCC         E008 
source      : 015L.tif 
name        : 015L 

....

我正试图找出一种使用马赛克的方法。这是我想出的解决方案。然而,在 7 个瓷砖组合后,计算机用完了磁盘 space。

Error: [merge] internal error: insufficient disk space (perhaps from temporary files?)

有没有更有效的方法来做到这一点?

你没有展示你用 lc_2000_tiles 做了什么。您是否提供 filename 参数?如果没有,输出将转到临时文件夹,也许这是在磁盘上 space 不多(而且效率低下)。您可以使用 terraOptions(tempdir = "....")

设置临时文件夹

此外,您需要 mosaic 还是可以使用 merge(相当于您有 non-overlapping 个区域)?如果是这样,您还可以使用 vrt:

v <- vrt(filelist_lc)

“VRT”是一个虚拟光栅。它可以将不同的文件(通常是相邻的 non-overlapping 个图块,但这不是必需的)视为单个数据源(文件)。有了它,你就可以做

x <- writeRaster(v, "combined.tif")