【发布时间】:2015-08-17 13:07:56
【问题描述】:
我有一个栅格砖,上面有岛屿的气候数据层,周围环绕着 NA 海洋细胞。我想将一些海洋单元格设置为附近海岸的值。这样做有很多麻烦。在我看来,代码应该如下所示,但我的内存不足。栅格大小约为 2500x2500。
# dummy stack with three layers
slogo <- stack(system.file("external/rlogo.grd", package="raster"))
# let's say cell 5 is the one I want to change
newvals <- 1000*(1:3)
for(i in 1:nlayers(slogo)) slogo[[i]][5] <- newvals[i]
随后的步骤是将栅格写入单独的 ascii 文件;因此,另一种 hacky 解决方案可能是剪切到文本文件中并替换单个值...
编辑:
也许有人可以通过重置内存分配限制来推荐解决方案?这是我在大型栅格上运行后显示的错误消息。
Error: cannot allocate vector of size 504.1 Mb
In addition: Warning messages:
1: In readBin(raster@file@con, what = dtype, n = nc, dsize, dsign, :
Reached total allocation of 3979Mb: see help(memory.size)
2: In readBin(raster@file@con, what = dtype, n = nc, dsize, dsign, :
Reached total allocation of 3979Mb: see help(memory.size)
3: closing unused connection 4 (C:\Users\jcw\AppData\Local\Temp\R_raster_jcw\r_tmp_2015-08-16_130255_2000_11926.gri)
4: In getBilData(object, r = startrow, nrows = nrows, c = startcol, :
Reached total allocation of 3979Mb: see help(memory.size)
5: In getBilData(object, r = startrow, nrows = nrows, c = startcol, :
Reached total allocation of 3979Mb: see help(memory.size)
6: In getBilData(object, r = startrow, nrows = nrows, c = startcol, :
Reached total allocation of 3979Mb: see help(memory.size)
7: In getBilData(object, r = startrow, nrows = nrows, c = startcol, :
Reached total allocation of 3979Mb: see help(memory.size)
【问题讨论】: