0

当我尝试将地理参考的 tif 文件添加到 R 中的 ggplots 时,我遇到了一个看似奇怪的插槽问题:使用加载光栅文件后,raster()我无法到达它的colortable-slot:

>>获取示例 tif 文件<<

raster1 <- raster(paste(workingDir, "/HUEK200_Durchlaessigkeit001_proj001.tif", sep="", collapse=""))
raster1@colortable  #or
slot(raster1, "colortable")

最后两行应该同样工作,但都会导致错误消息:

Error in slot(raster1, "colortable") : 
  no slot of name "colortable" for this object of class "RasterLayer"

这很令人困惑,因为通过对属性的一瞥attributes(raster1)清楚地列出了该插槽:

Slot "colortable":
  [1] "#FFFFFF" "#000000" "#B49ED7" "#9B7DCF" "#9EAAD7" "#B2BEEB" "#B4EBB4"
  [8] "#F5E1B5" "#CCB792" "#B9A08C" "#0070FF" "#0000C8" "#F8F8F8" "#DBF5FF"
 [15] "#B14D00" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [22] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [29] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [36] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [43] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [50] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [57] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [64] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [71] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [78] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [85] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [92] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
 [99] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[106] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[113] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[120] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[127] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[134] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[141] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[148] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[155] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[162] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[169] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[176] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[183] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[190] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[197] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[204] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[211] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[218] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[225] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[232] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[239] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[246] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
[253] "#000000" "#000000" "#000000" "#000000"

首先是我做错了什么还是可能是一个错误?我怎样才能最终访问颜色表?我从调用中知道plot(raster1)它应该可以工作,因为该图显示了正确的颜色集。此外:通常,S4object@someslot在管理空间多边形对象时,-方法对我来说效果很好。

编辑:colortable尝试访问其他插槽列表时会出现相同的错误attributes(raster1)

谢谢你的帮助!

4

1 回答 1

2

我现在自己找到了答案。我只是误读了attributes(raster1). colortable-slot 不是直接(一阶)光栅对象接口的一部分,如果你可以在 R 中这样称呼它的话。相反,它是这样列出的legend

attr(raster1, "legend")@colortable

R 中的引用总是让我感到惊讶!:)

于 2013-10-04T16:34:00.230 回答