3D 栅格堆栈图

3D raster stack plot

我有一个包含 2 个图层的栅格堆栈,对应于 2 个高程。每层都是一个栅格,Lon 和 Lat 坐标值为 1(所有缺失值均为 NA),形成多边形。 RasterStack example

r1<-raster(xmn = 2.5, xmx = 3.3, ymn = 42, ymx = 42.5, nrows = 28, ncols = 33)
r2<-raster(xmn = 2.5, xmx = 3.3, ymn = 42, ymx = 42.5, nrows = 28, ncols = 33)

a<-c(421, 422, 424, 453, 454, 455, 456, 457, 485, 486, 487, 488, 489, 513, 514, 515, 516, 517, 518, 519, 546, 547, 548, 549, 550, 579, 580, 581, 582, 583, 613, 614, 615, 646, 647, 648, 649, 680, 681, 682)
r1[a]<-1
b<-c(514, 515, 516, 547, 548, 549, 550, 613, 614, 615, 647, 648, 649)
r2[b]<-1

st<-stack(r1,r2)

有什么方法可以制作 3D 图,根据图层显示不同高度的每个多边形吗? (x=LON, Y=LAT, Z= nlayer)

我已经实现了第 1 层和第 2 层的 scatter3D 图 Scatter3D example,但我想将它们显示为多边形,以查看区域如何在整个垂直方向上重叠。

你可以试试

library(raster)
library(plot3D)
f <- function(x, offset=0, add=FALSE) { 
  poly <- rasterToPolygons(x, dissolve = T)
  coords <- poly@polygons[[1]]@Polygons[[1]]@coords
  polygon3D(
    x=coords[,1], 
    y=coords[,2], 
    z=rep(offset,nrow(coords)), 
    xlim=lims[1:2],
    ylim=lims[3:4],
    zlim=lims[5:6], 
    add=add, 
    col="red",
    theta = 0
  )
}
lims <- c(as(extent(st),"vector"), 0, 3000)
f(st[[1]],0*1000,F)
for (x in 2:nlayers(st)) 
  f(st[[x]],x*1000,T)