【问题标题】:raster data: memory issue with R - cannot allocate vector栅格数据:R 的内存问题 - 无法分配矢量
【发布时间】:2021-03-22 01:22:48
【问题描述】:

大家, 我正在尝试使用 rayshader 包获取 3D 地图,但显然该文件太大而无法由 RStudio 处理。以下是部分代码:

(...)

elevation = raster::merge(srtm,srtm2) #works fine
height_shade(raster_to_matrix(elevation)) %>% plot_map() #works fine
 
piecergb <- raster::stack(piece) #works fine

setValues(piecergb, scales::rescale(values(piecergb), to = c(0, 255)))

   Error: cannot allocate vector of size 11.9 Gb

所以,我首先检查了我的 RStudio 的容量:

memory.size()
[1] 27720.21

memory.limit()
[1] 2e+05 ###this I have previously changed with memory.limit(size=200000)

并调用 gc() 来清理我的会话

gc()
            used   (Mb) gc trigger    (Mb)   max used    (Mb)
Ncells   2766617  147.8    4954078   264.6    4954078   264.6
Vcells 404719527 3087.8 3551300168 27094.3 3774733748 28799.0

然后我重新启动了我的 RStudio,重新定义了内存限制并再次尝试。但我仍然收到相同的错误消息。有人知道如何解决这个问题吗?到目前为止我还没有找到其他解决方案,无法继续绘制地图。

我的系统信息是:

Sys.info()
       sysname        release        version       nodename        machine          login           user effective_user 
     "Windows"       "10 x64"  "build 18363"        "NSF85"       "x86-64"      "install"      "install"      "install" 

非常感谢您

阿德里安娜

【问题讨论】:

    标签: r memory raster r-raster


    【解决方案1】:

    在这一行中,您使用 values 将所有像元值从 Raster* 对象 piecergb 读取到内存中,然后使用 setValues 将它们再次分配给 Raster*。

    x <- setValues(piecergb, scales::rescale(values(piecergb), to = c(0, 255)))
    

    如果您的数据集很大,这会导致问题。相反,请使用 raster 包中的方法(这些方法可以避免该问题)。我认为你所做的相当于

    x <- clamp(piecergb, 0, 255)
    

    另见?reclassify

    【讨论】:

    • 我尝试了您的方法并且它有效,但不适用于我脚本的以下步骤。我尝试了raster::plotRGB(xt, scale=255^2)(其中 xt 是clamp(piecergb, 0, 255) 的输出),但我收到了Error in (function (classes, fdef, mtable): unable to find an inherited method for function ‘plotRGB’ for signature ‘"RasterLayer"’ 的消息,所以我认为它对rayshader 管道不起作用,即使我可以使用内存问题!如果您在这方面有任何其他想法,我很乐意知道,但您的帮助已经足以回答我发布的问题!
    • plotRGB 需要三层(R、G、B,在 RasterStack 或 RasterBrick 中)。显然piecergb 只有一个(它是一个 RasterLayer)。 clamp 不影响这一点。
    猜你喜欢
    • 2020-09-16
    • 2013-05-26
    • 2020-03-05
    • 2020-07-27
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    相关资源
    最近更新 更多