【发布时间】:2020-03-22 11:04:50
【问题描述】:
我在内存中有一个现有光栅砖对象,例如:
library(raster)
#> Loading required package: sp
set.seed(84832)
r1 <- raster(matrix(runif(4), ncol = 2))
r2 <- raster(matrix(runif(4), ncol = 2))
b <- brick(r1, r2)
b
#> class : RasterBrick
#> dimensions : 2, 2, 4, 2 (nrow, ncol, ncell, nlayers)
#> resolution : 0.5, 0.5 (x, y)
#> extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : memory
#> names : layer.1, layer.2
#> min values : 0.45211936, 0.04150152
#> max values : 0.9454290, 0.2539412
有没有办法直接保存并将其转换为从光盘读取的砖块?像这样的事情(失败):
b <- brick(b, "b.grd")
#> Warning in .local(x, ...): NAs introduced by coercion
#> Warning in .local(x, ...): NAs introduced by coercion
#> Error in rep(Inf, nl): invalid 'times' argument
b
#> class : RasterBrick
#> dimensions : 2, 2, 4, 2 (nrow, ncol, ncell, nlayers)
#> resolution : 0.5, 0.5 (x, y)
#> extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : memory
#> names : layer.1, layer.2
#> min values : 0.45211936, 0.04150152
#> max values : 0.9454290, 0.2539412
与将砖写入文件,然后将其读回并覆盖现有砖相反:
writeRaster(b, "b.grd")
b <- brick("b.grd")
b
#> class : RasterBrick
#> dimensions : 2, 2, 4, 2 (nrow, ncol, ncell, nlayers)
#> resolution : 0.5, 0.5 (x, y)
#> extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)
#> crs : NA
#> source : memory
#> names : layer.1, layer.2
#> min values : 0.45211936, 0.04150152
#> max values : 0.9454290, 0.2539412
由reprex package (v0.3.0) 于 2019 年 11 月 27 日创建
【问题讨论】: