R - Slot无法访问?

时间:2013-10-04 16:16:15

标签: r colors raster slot

当我尝试将 georeferenced tif-files 添加到R中的ggplots时,我遇到了一个看似奇怪的插槽问题:使用{加载光栅文件后{1}}我无法访问raster() - 插槽:

>>Grab the example tif-file<<

colortable

最后两行shoudl工作正常但导致错误消息:

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)

首先是我做错了什么或者它是一个错误?我怎么能最终获得colortable?我知道通过调用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访问其他广告位时,会出现同样的错误。

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

我现在已经找到了答案。我只是误读了attributes(raster1)的(不完全明显的)输出。 colortable - 插槽不是直接(一阶)栅格对象接口的一部分,如果你可以在R中调用它,那么它就像legend一样列在其中:

attr(raster1, "legend")@colortable

R中的参考文献总是让我感到惊讶! :)