0

我正在使用 ForestTools 包从 chm 栅格中分割树木,并计算树冠面积。该软件包工作得很好,但我无法计算 30x30m 特定网格内所有冠区域的总和。有没有办法定义自定义求和函数,这样我就可以得到 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, CHM = schm, 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)
4

0 回答 0