我正在使用 rLiDAR 包使用 LiDARForestStand 函数绘制林地,我今天的目标是使用 rgl.widget 函数为林地创建交互式 .html 文件,但我不确定如何嵌入 for 循环和 LiDARForestFunction 进入创建 HTML 文件的过程。用于此目的的具体代码行如下,并包含来自 rgl 文档的示例代码,因此未对其进行修改。当我使用 plot3d 函数时,它只是绘制散点图,所以我猜 rgl 小部件也只会创建这个散点图的 HTML,而不是林地。
**更新(最少的可重现代码)**
#=======================================================================#
#=======================================================================#
#Plotting a forest plantation stand in virtual 3-D space
#=======================================================================#
# Setup the forest stand dimensions
xlength<-30 # x length
ylength<-20 # y length
# Set the space between trees
sx<-3 # x space length
sy<-2 # y space length
# Tree location grid
XYgrid <- expand.grid(x = seq(1,xlength,sx), y = seq(1,ylength,sy))
# Getting the number of trees
N_Trees<-nrow(XYgrid)
# Plot a virtual Eucalyptus forest plantation stand using the halfellipsoid tree crown shape
# Setup the stand tree parameters
meanHCB<-5 # mean height at canopy base
sdHCB<-0.1 # standard deviation of the height at canopy base
HCB<-rnorm(N_Trees, mean=meanHCB, sd=sdHCB) # height at canopy base
CL<-HCB # tree crown height
CW<-HCB*0.6 # tree crown diameter
library(rgl)
library(raster)
library(rLiDAR)
open3d() # open a rgl window
# Plotting the stand
for( i in 1:N_Trees){
LiDARForestStand(crownshape = "halfellipsoid", CL = CL[i], CW = CW[i],
HCB = HCB[i], X = XYgrid[i,1], Y = XYgrid[i,2], dbh = 0.4,
crowncolor = "forestgreen", stemcolor = "chocolate4",
resolution="high", mesh=TRUE)
}
plot3d(x = XYgrid[i,1], Y = XYgrid[i,2], xlab = "X Coord", ylab = " Y Coord", zlab = "Height")
scene3d()
#Creating an interactive HTML window
save <- getOption("rgl.useNULL")
options(rgl.useNULL=TRUE)
example("plot3d", "rgl")
widget <- rglwidget()
if (interactive())
widget
# Save it to a file. This requires pandoc
filename <- tempfile(fileext = ".html")
htmlwidgets::saveWidget(rglwidget(), filename)
browseURL(filename)