当我尝试将地理参考的 tif 文件添加到 R 中的 ggplots 时,我遇到了一个看似奇怪的插槽问题:使用加载光栅文件后,raster()
我无法到达它的colortable
-slot:
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)
。
谢谢你的帮助!