【问题标题】:Creating a raster dataset but plot error创建栅格数据集但绘图错误
【发布时间】:2017-09-01 07:08:30
【问题描述】:

我在学习 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

我该如何解决这个问题?

【问题讨论】:

    标签: r r-raster rgdal


    【解决方案1】:

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

    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")
    

    【讨论】:

    • 我不明白为什么我需要给出一个名字作为例子,没有给出一个名字,它运行。重新采样栅格后,据我所知,它不会转换为新栅格,对吧?
    • 使用resample 创建了一个新栅​​格,但您没有存储它。因此,该函数不会给出错误消息,因为它完成了这项工作。但是你不能使用创建的栅格,因为你不知道它在哪里......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多