创建栅格数据集但绘图错误

Creating a raster dataset but plot error

我在学习 R tool 并且我在学习一个例子,但是尽管我做了所有相同的事情,但我在 the plot raster 期间遇到了错误。

代码如下:

library(raster)
library(rgdal)

myRaster1 <- raster(nrow=4, ncol=4)
myRaster1[]<- 1:ncell(myRaster1)
myRaster2=raster(nrow=8, ncol=8)
resample(myRaster1, myRaster2, method='bilinear')
plot(myRaster2, main="Raster with 32 pixels")

这里是错误警告:

Error in .plotraster2(x, col = col, maxpixels = maxpixels, add = add,  : 
  no values associated with this RasterLayer

我该如何解决这个问题?

您需要为重新采样的栅格命名:

library(raster)
library(rgdal)

myRaster1 <- raster(nrow=4, ncol=4)
myRaster1[]<- 1:ncell(myRaster1)
myRaster2=raster(nrow=8, ncol=8)
myRaster1.resampled <- resample(myRaster1, myRaster2, method='bilinear')
plot(myRaster1.resampled, main="Raster with 32 pixels")