问题描述
当我试图添加地理参考的tif文件到我的ggplots在R,我遇到一个看似奇怪的插槽问题:使用 raster()
我无法到达 colortable
-slot:
As I am trying to add georeferenced tif-files to my ggplots in R, I have encountered a seemingly weird problem with slots: After loading the raster file using raster()
I can't reach its colortable
-slot:
: p>
>>Grab the example tif-file<<:
raster1 <- raster(paste(workingDir, "/HUEK200_Durchlaessigkeit001_proj001.tif", sep="", collapse=""))
raster1@colortable #or
slot(raster1, "colortable")
最后两行显示同样的错误信息:
The two last lines shoudl work equally but result both in the error message:
Error in slot(raster1, "colortable") :
no slot of name "colortable" for this object of class "RasterLayer"
混淆,因为通过属性(raster1)
很清楚地列出了属性:
This is confusing because a small glimpse into the attributes via attributes(raster1)
clearly lists exactly that slot:
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"
是我是谁在做错事在第一个地方,还是它是一个错误?如何才能终于访问colortable?我知道从调用 plot(raster1)
它应该工作,因为情节显示正确的颜色集。此外:通常,在管理空间多边形对象时, S4object @ someslot
-approach对我来说很好。
Is it me who is doing something wrong in the first place or could it be a bug? And how can I finally access the colortable? I know from calling plot(raster1)
that it should work because the plot displays the correct color-set. Furthermore: Normally, the S4object@someslot
-approach works just fine for me when managing spatial polygon objects.
:
当属性(raster1)
尝试访问其他插槽列表时,在 colortable
Beside colortable
the same error appears when trying to access other slots listes by attributes(raster1)
.
感谢您的帮助!
推荐答案
我现在。我只是误读从属性(raster1)
的(不完全明显)输出。 colortable
-slot不是直接(第一顺序)光栅对象接口的一部分,如果你可以调用它在R中。列在 legend
如下:
I have found the answer myself now. I simply misread the (not completely obvious) output from attributes(raster1)
. The colortable
-slot is not part of the direct (first order) raster-object-interface, if you can call it liek that in R. Rather it is listed in the legend
like so:
attr(raster1, "legend")@colortable
R中的引用总是会让我感到惊讶! :)
References in R always tend to surprise me! :)
这篇关于R - 槽不可达?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!