3D光栅堆栈图

时间:2017-04-15 12:45:28

标签: r plot 3d stack raster

我有一个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 example获得了一个scatter3D图,但我想将它们显示为多边形,以了解区域在整个垂直区域内的重叠方式。

1 个答案:

答案 0 :(得分:0)

你可以尝试

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)

enter image description here