堆栈和砖功能错误,尽管所有的栅格都已被

stack and brick function error despite all of the rasters have been

大家好..

我有 13 个生物气候变量(.tiff 格式),我将使用 dismo 包来执行 sdm。 我遵循了 Robert J. Hijmans 和 Jane Elith 编写的教程。 但是,当我尝试堆叠所有变量时,出现以下错误

Error in .local(.Object, ...) :

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file.

我的文件的所有坐标系、范围和像元大小都已调整,所以它们都是一样的.. 当我尝试使用替代砖功能时,出现以下错误:

Error in .rasterObjectFromFile(x, objecttype = "RasterBrick", ...) : Cannot create a RasterLayer object from this file. In addition: There were 12 warnings (use warnings() to see them)

我使用了 warning() 消息,但它是空的..

对于此类错误的可能原因,你们中的任何人有任何提示吗? 我试过 google 它,但不幸的是,没有答案可以解决它。 提前谢谢你..

此处显示的是成绩单的一部分

#setting the workspace
 setwd("D:/Riset/MaxentSelaginella/newpaperproject_part2/MakalahVI/Workspace_R")

#Loading Libraries
 library("sp")
 library("raster")
 library("maptools")
 library("rgdal")
 library("dismo")
 library("rJava")

 #open the csv file
 obs.data <- read.csv(file = "data3/Selaginella_plana.csv", sep = ",")

 #open Environmental Data
 files <- list.files(path = "data3/tif/", pattern = ".tif", full.names=TRUE)

 #stacking all the files
  predictors <- brick(files)

我猜你需要使用 stack 而不是 brick。根据 brick 帮助,实际上:

A RasterBrick is a multi-layer raster object. They are typically created from a multi-layer (band) file; but they can also exist entirely in memory. They are similar to a RasterStack (that can be created with stack), but processing time should be shorter when using a RasterBrick. Yet they are less flexible as they can only point to a single file.

因此,如果我们尝试“堆叠”多个文件:

library(raster)
r <- raster(ncols = 100, nrows = 100, vals = 1:10000)
rfile1 <- tempfile(fileext = ".tif")
writeRaster(r, filename = rfile1)
rfile2 <- tempfile(fileext = ".tif")
writeRaster(r, filename = rfile2)

files_to_stack <- c(rfile1, rfile2)

这失败了:

brick(files_to_stack)
#> Warning in if (x == "" | x == ".") {: the condition has length > 1 and only
#> the first element will be used
#> Warning in if (!start %in% c("htt", "ftp")) {: the condition has length > 1
#> and only the first element will be used
#> Warning in if (fileext %in% c(".GRD", ".GRI")) {: the condition has length
#> > 1 and only the first element will be used
#> Warning in if (!file.exists(x)) {: the condition has length > 1 and only
#> the first element will be used
.....
#> Error in .rasterObjectFromFile(x, objecttype = "RasterBrick", ...): Cannot create a RasterLayer object from this file.

虽然这有效:

stack(files_to_stack)
#> class       : RasterStack 
#> dimensions  : 100, 100, 10000, 2  (nrow, ncol, ncell, nlayers)
#> resolution  : 3.6, 1.8  (x, y)
#> extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
#> names       : file46e41bcd78e3, file46e43ea75bad 
#> min values  :                1,                1 
#> max values  :            10000,            10000

如果您想 brick 进一步提高“效率” 处理,你可以将不同的"layers"保存为多波段tiff,然后使用brick打开:

rfile_multi <- tempfile(fileext = ".tif")
writeRaster(stack(files_to_stack), filename = rfile_multi)
brick(rfile_multi)

#> class       : RasterBrick 
#> dimensions  : 100, 100, 10000, 2  (nrow, ncol, ncell, nlayers)
#> resolution  : 3.6, 1.8  (x, y)
#> extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
#> data source : D:\RTemp\RtmpacXztJ\file4808784f268c.tif 
#> names       : file4808784f268c.1, file4808784f268c.2 
#> min values  :                  1,                  1 
#> max values  :              10000,              10000

reprex package (v0.2.1)

于 2018-11-10 创建