微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在 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 举报,一经查实,本站将立刻删除。