library(raster)
library(rgdal)
library(elevatr)
library(rgeos)
library(leaflet)
library(RColorBrewer)
library(rgl)
r1 <- raster()
s1 <- stack()
base <- 'https://portal.opentopography.org/API/globaldem?demtype=AW3D30'
api_key <- '<API-KEY>'
tmp_south <- 36.738884
tmp_north <- 38.091337
tmp_west <- -120.168457
tmp_east <- -118.465576
url <- paste0(base, '&south=', tmp_south, '&north=', tmp_north, '&west=', tmp_west, '&east=', tmp_east, '&API_Key=', api_key)
download.file(url, "./display.tif", mode = "wb")
r1 <- raster(system.file("display.tif"), package="raster")
image(r1)错误:
.rasterObjectFromFile中的错误(x,band = band,objecttype = " RasterLayer“):无法从该文件创建RasterLayer对象。
发布于 2022-10-17 15:47:22
问题是你打电话给system.file()。
我注意到在光栅医生中,这是在一个示例中使用的:
filename <- system.file("external/test.grd", package="raster")但是,system.file()的存在是为了查找R包文件的名称,而不是创建文件路径对象。在本教程中使用它的原因是加载与包一起安装的演示数据。该教程说:
不要使用您自己的文件的system.file结构(只需键入文件名;不要忘记斜杠)。
raster()函数接受第一个参数,即字符向量。你可以:
r1 <- raster("./display.tif")然后,您可以成功地运行:
image(r1)

https://stackoverflow.com/questions/74099433
复制相似问题