简体   繁体   English

.rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",: 无法从此文件创建 RasterLayer object

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

I have this instruction in my script:我的脚本中有这条指令:

wc25 <- stack(list.files(path="./Rhaebo/Bio_PresWC1.4/", pattern = "asc", full.names = T))

but when I run it, it throws me the following message:但是当我运行它时,它会抛出以下消息:

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

I have the following packages loaded:我加载了以下包:

library(ecospat)
library(sf)
library(ggplot2)
library(maptools)
library(sp)
library(raster)
library(rgeos)
library(dismo)
library(ENMeval)
library(rJava)
library(SSDM)
library(usdm)
library(sdm)
library(plyr)
library(rgdal)
library(MigClim)
library(spatialEco)
library(biomod2)
library(devtools)
library(ENMTools)
library(RColorBrewer)
library(terra)
library(reshape2)
library(ggplot2)
library(ggstatsplot)
library(rasterVis)
library(sf)

Does anyone know what could cause this problem?有谁知道什么可能导致这个问题?

The first thing you need to do is to only load the package you actually need for this line of code (ie the raster package) --- and generally, avoid loading packages that are not used in your script.您需要做的第一件事是仅加载这行代码(即光栅包)实际需要的 package --- 通常,避免加载脚本中未使用的包。 If all these packages are used in your script, then you script is surely too long and complicated and you should cut it into smaller pieces.如果所有这些包都用在你的脚本中,那么你的脚本肯定太长太复杂了,你应该把它分成更小的部分。

And you need to inspect (and show) what is returned by list.files .您需要检查(并显示) list.files返回的内容。 Probably some file that is not a raster>可能是一些不是光栅的文件>

You should use pattern = "\\.asc$" as your pattern.您应该使用pattern = "\\.asc$"作为您的模式。 \\. is for the dot, .是点, . is a wildcard.是一个通配符。 $ means "ends on" $表示“结束于”

ff <- list.files(path="./Rhaebo/Bio_PresWC1.4/", pattern = "\\.asc$", full.names = TRUE))
ff
s <- raster::stack(ff)

Or要么

x <- terra::rast(ff)

And it is a bad idea (very inefficient) to use ascii files.使用 ascii 文件是一个坏主意(非常低效)。 See raster::getData for better access to the old WorldClim data that you are using and geodata::worldclim for the current version.请参阅raster::getData以更好地访问您正在使用的旧 WorldClim 数据和当前版本的geodata::worldclim

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM