在 ForestTools R 包中定义冠面积总和的自定义函数?

问题描述

我正在使用 ForestTools 包从 chm 栅格中分割树木,并计算树冠面积。该软件包运行良好,但我无法计算 30x30 米特定网格内所有冠部区域的总和。有没有办法定义自定义求和函数,以便我可以获得 30x30m 的每个单元格中的冠部区域总和。 我使用的代码如下,但总和计算产生错误的值。

if (!require(ForestTools) ){ install.packages("ForestTools",dependencies=TRUE);library(ForestTools)}
lin <- function(x){x * 0.3}
ttops <- vwf(CHM = schm,winFun = lin,minHeight = 1.5) # vwf function is variable window function based on developed by Popescu and Wynne (2004)
crowns <- mcws(treetops = ttops,CHM = schm,minHeight = 1,verbose = FALSE)
# Plot crowns
plot(crowns,col = sample(rainbow(50),length(unique(crowns[])),replace = TRUE),legend = FALSE,xlab = "",ylab = "",xaxt='n',yaxt = 'n')

# Create polygon crown map
crownspoly <- mcws(treetops = ttops,format = "polygons",minHeight = 1.5,verbose = FALSE)
# Compute average crown diameter
crownspoly[["crownDiameter"]] <- sqrt(crownspoly[["crownArea"]]/ pi) * 2
# Mean crown diameter
mean(crownspoly$crownDiameter)
writeOGR(obj=crownspoly,dsn=getwd(),layer="crowns_final",driver="ESRI Shapefile")

# Summed crown areas and quantile per grid
crowns_summed<-shapefile("crowns_final")
gridpolygon<-shapefile("X")
quant98 <- function(x,...) quantile(x,c(.98),na.rm = TRUE)
custFuns <- list(quant98,sum)
names(custFuns) <- c("98thQuantile","Sum")
# Generate statistics for crown areas and tree heights
Grid_summary<-sum(crowns_summed,areas=gridpolygon,variables = "area",statFuns=custFuns)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)