是否有R函数用于绘制单个rasterLayers?

时间:2019-03-28 17:53:17

标签: r r-raster

我有以下rasterLayer:

@ServerEndpoint
public class WebsocketServer
{
  @OnOpen
  public void onOpen(Session session)
  {
    // ...
  }

  @OnMessage
  public void onMessage(Session session, String message)
  {
    // ...
  }

  @OnMessage
  public void onMessage(Session session, PongMessage pongMessage)
  {
    // ...
  }

  @OnError
  public void onError(Throwable error)
  {
    // ...
  }

  @OnClose
  public void onClose(Session session)
  {
    // ...
  }
}

当我尝试绘制它时,出现以下错误:

onOpen()

这是什么意思?我使用的功能不正确吗?还是应该使用其他功能?

编辑:onMessage()的详细信息:

onOpen()

RStudio在全球环境中将> patK[["199006"]][[1]] class : RasterLayer dimensions : 640, 960, 614400 (nrow, ncol, ncell) resolution : 1, 1 (x, y) extent : 0, 960, 0, 640 (xmin, xmax, ymin, ymax) coord. ref. : NA data source : in memory names : layer values : 1, 1 (min, max) 描述为“大列表(10个元素,235.6 mb)”。 > plot(patK[["199006"]][[1]]) Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' 的每个元素的类型均为patK,而每个元素的类型均为> names(patK) [1] "199006" "199007" "199008" "199009" "199010" "199011" "199013" "199014" "199015" "199016" > rapply(patK, class) 1990061 1990062 1990063 1990064 1990065 1990066 1990067 1990068 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990069 19900610 1990071 1990072 1990073 1990074 1990075 1990076 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990077 1990078 1990079 19900710 1990081 1990082 1990083 1990084 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990085 1990086 1990087 1990088 1990089 19900810 1990091 1990092 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990093 1990094 1990095 1990096 1990097 1990098 1990099 19900910 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990101 1990102 1990103 1990104 1990105 1990106 1990107 1990108 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990109 19901010 1990111 1990112 1990113 1990114 1990115 1990116 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990117 1990118 1990119 19901110 1990131 1990132 1990133 1990134 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990135 1990136 1990137 1990138 1990139 19901310 1990141 1990142 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990143 1990144 1990145 1990146 1990147 1990148 1990149 19901410 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990151 1990152 1990153 1990154 1990155 1990156 1990157 1990158 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990159 19901510 1990161 1990162 1990163 1990164 1990165 1990166 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer" 1990167 1990168 1990169 19901610 "RasterLayer" "RasterLayer" "RasterLayer" "RasterLayer"

2 个答案:

答案 0 :(得分:1)

这里是带有RasterLayer对象列表列表的复制示例

library(raster)
r <- raster(system.file("external/test.grd", package="raster"))
s <- list(r, r, r)
x <- list(s, s, s)
names(x) <- c("A", "B", "C")

你可以

plot(x[["A"]][[1]])

rr <- x[["A"]][[1]]
plot(rr)

因此patK还有其他问题---但我无法猜测是什么。即使您无法显示str(patK),也可以显示names(patK)rapply(patK, class)

此外,当您这样做时会发生什么

x <- patK[["199006"]][[1]]
x
plot(x)

也许另一个软件包正在产生问题。您可以在干净的环境中尝试此操作吗,除了raster之外没有加载任何程序包。尝试使用raster::plot(),然后看看showMethods("plot")(是否有某种方法为某个软件包定义了列表的方法?)

答案 1 :(得分:0)

library(raster)
r <- system.file("external/test.grd", package="raster")
s <- stack(r, r, r)
plot(s[[1]])

根据您的情况,尝试:

plot(patk[[1]])