是否可以使用rLiDAR包装中的LiDARForestStandFunction为林分创建交互式.html文件?

问题描述 投票:-1回答:1

我正在使用rLiDAR包通过LiDARForestStand函数绘制林分,我今天的目标是使用rgl.widget函数为林分创建一个交互式.html文件,但是我不确定如何嵌入for循环和LiDARForestFunction进入创建HTML文件的过程。用于此目的的特定代码行如下,其中包含rgl文档中的示例代码,因此尚未对其进行修改。当我使用plot3d函数时,它只是绘制散点图,所以我猜rgl小部件也将创建此散点图的HTML,而不是林分。enter image description here

**更新(最小可复制代码)**

   #=======================================================================#
#=======================================================================#
#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)
r rgl lidar lidar-data
1个回答
0
投票

我终于使用以下代码解决了。我必须进行一些更改。谢谢大家的帮助。

#=======================================================================#
#=======================================================================#
#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)
library(rglwidget)
#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)
}
HTML <- rglwidget(elementId = "Plot3D",width=500, height=300)
# Exporting HTML file
htmlwidgets::saveWidget(rglwidget(), "D:/Summer_Work/Test.html")
© www.soinside.com 2019 - 2024. All rights reserved.