r - 有没有办法使用 rLiDAR pakcage 中的 LiDARForestStandFunction 为林分创建交互式 .html 文件?
问题描述
我正在使用 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)
解决方案
我终于用下面的代码解决了。我不得不做出一些改变。感谢大家的帮助。
#=======================================================================#
#=======================================================================#
#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")
推荐阅读
- syntax-highlighting - 为什么 CLion 不以不同的方式突出 Doxygen 评论?
- c# - 当多个用户同时上传到数据库时,AjaxFileUpload 临时数据保存到错误的帐户
- python - 无法使用 Python 绘制包含二进制值的列的分布
- c# - 如何在 c# 中拍摄没有 vsync 的 directX11 游戏的良好屏幕截图
- rest - 如何通知客户端返回的 HTTP 资源表示已弃用?
- pygame - 在 pygame 中遇到碰撞检测问题
- sql - 关于加入条件的问题。需要比较从 A 点到 B 点的运输数量
- sql - pgAdmin 4 数据库还原
- flutter - 由于错误 VERBOSE.dart 错误,无法运行颤振项目,隔离错误
- mysql - 查询运行 14 天并继续 - 如何优化?