无法在 R 中打开创建的栅格 [英] Can not open created raster in R

查看:125
本文介绍了无法在 R 中打开创建的栅格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个与错误相关的问题:

I have two issues related to the error:

第一:我有一个合并的 dem 层和多个 shapefile,我创建了一个蒙版 shapefile 边界列表,我能够绘制所有这些边界,除了最大的第一个"一:

first: I have one merged dem layer and multiple shapefiles, I create a list of masked shapefiles boundary, I was able to plot all of them except one "the first one" which is the biggest one:

> plot(DEM_masked_list[[1]])

Error in file(fn, "rb") : cannot open the connection
In addition: Warning message:
  In file(fn, "rb") :
  cannot open file '/private/var/folders/2w/rjzwcrbn3pg0jmsrfkz7n52h0000gn/T/RtmpkL8Ot5/raster/r_tmp_2018-01-29_014745_982_20879.gri': No such file or directory

我注意到第一个 dem 的数据源与其他所有的不同,这可能是由于它的尺寸较大(509141570 个单元格)!!

I notice the data source of the first dem differ from all the others, that might be due to the larger size of it (509141570 no. of the cell)!!

DEM_masked_list

[[1]]
class       : RasterLayer 
dimensions  : 20015, 25438, 509141570  (nrow, ncol, ncell)
resolution  : 9.259259e-05, 9.259259e-05  (x, y)
extent      : -70.43231, -68.07694, 45.98676, 47.84  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : /private/var/folders/2w/rjzwcrbn3pg0jmsrfkz7n52h0000gn/T/RtmpkL8Ot5/raster/r_tmp_2018-01-29_014745_982_20879.grd 
names       : layer 
values      : 121.4266, 856.6606  (min, max)


[[2]]
class       : RasterLayer 
dimensions  : 9043, 9896, 89489528  (nrow, ncol, ncell)
resolution  : 9.259259e-05, 9.259259e-05  (x, y)
extent      : -69.76269, -68.84639, 46.23528, 47.07259  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : in memory
names       : layer 
values      : 187.9911, 650.0044  (min, max)

第二:我在一层(DEM_merged)中合并了 25 个单独的 dem,数据源也没有存储在内存中,我能够绘制它并使用它一天是2018-01-28(出现在数据源中),然后出现同样的错误.

Second: I merged 25 separate dem in one layer (DEM_merged), the data source also not stored in memory, I was able to plot it and work with it for one day which is 2018-01-28 (appear in the data source), then the same error appeared.

> DEM_merge
class       : RasterLayer 
dimensions  : 75612, 75612, 5717174544  (nrow, ncol, ncell)
resolution  : 9.259259e-05, 9.259259e-05  (x, y)
extent      : -74.00056, -66.99944, 40.99944, 48.00056  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : /private/var/folders/2w/rjzwcrbn3pg0jmsrfkz7n52h0000gn/T/RtmpkL8Ot5/raster/r_tmp_2018-01-28_163201_982_66674.grd 
names       : layer 
values      : -81.04944, 1915.734  (min, max)

> plot(DEM_merge)
Error in file(fn, "rb") : cannot open the connection
In addition: Warning message:
  In file(fn, "rb") :
  cannot open file '/private/var/folders/2w/rjzwcrbn3pg0jmsrfkz7n52h0000gn/T/RtmpkL8Ot5/raster/r_tmp_2018-01-28_163201_982_66674.gri': No such file or directory
> 

有什么办法可以解决吗?我觉得 Raster 包及其存储数据的方式存在一些问题,我尝试重新安装 Raster 包,重新安装 R,即使我在发布 这里 但仍然是同样的问题,感谢您的帮助!

Is there any way to fix that? I feel there is some issue with Raster package and the way that it store the data, I tried to reinstall Raster package, reinstall R, even I used a different computer after I post here but still the same issue, Appreciate your help!!

推荐答案

将大型 Raster* 对象的值写入文件,以避免内存限制问题.如果您没有明确提供文件名,它们将存储在临时数据文件夹中,当 R 会话结束时,该文件夹将被删除.

The values of large Raster* objects are written to file, to avoid memory limitation problems. If you do not explicitly provide a filename, they are stored in the temporary data folder that will be removed when the R session ends.

我猜你创建了 RasterLayers 并将列表保存到磁盘,然后关闭了 R?或者您在再次打开 R 时重新加载了会话?

I am guessing you created the RasterLayers and saved the list to disk, and closed R? Or perhaps you reloaded your session when opening R again?

只是猜测,但如果是这样,大栅格的值应该确实消失了.为避免发生这种情况,您可以尝试使用 readAll(不推荐)将所有值强制写入内存,或者使用 writeRaster

Just guessing, but if so, the values of the large raster should indeed have disappeared. To avoid that from happening, you can either try to force all values into memory with readAll (not recommended), or write them to a permanent file with writeRaster

这篇关于无法在 R 中打开创建的栅格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆