I wrote a specific function to calculte metrics on a catalog but this function (myMetrics) work with a lasLAS file but don't work with a catalog ?
myMetrics = function(las, ...) { UseMethod("myMetrics", las) }
myMetrics.LAS <- function(las){ metrics <- list( min_x <- min(las@data$X), max_x <- max(las@data$X), min_y <- min(las@data$Y), max_y <- max(las@data$Y), min_z <- min(las@data$Z), max_z <- max(las@data$Z), min_classification <- min(las@data$Classification), max_classification <- max(las@data$Classification) ) names(metrics) <- c( "min_x", "max_x", "min_y", "max_y", "min_z", "max_z", "min_classification", "max_classification" ) return(metrics) }
myMetrics.LAScluster <- function(cluster)
{
las <- readLAS(cluster)
if (is.empty(las)) return(NULL)
metrics <- lasmetrics(las, ~myMetrics(las))
return(metrics)
}
opt_chunk_buffer(ctg) <- 0 opt_chunk_size(ctg) <- 0 opt_output_files(ctg) <- "" plots_metrics <- catalog_apply(ctg, lasmetrics, func = .myMetrics(ctg))
myMetrics = function(las, ...)
{
UseMethod("myMetrics", las)
}
myMetrics.LAS <- function(las){
metrics <- list(
min_x <- min(las@data$X),
max_x <- max(las@data$X),
min_y <- min(las@data$Y),
max_y <- max(las@data$Y),
min_z <- min(las@data$Z),
max_z <- max(las@data$Z),
min_classification <- min(las@data$Classification),
max_classification <- max(las@data$Classification)
)
names(metrics) <- c(
"min_x", "max_x", "min_y", "max_y", "min_z", "max_z", "min_classification", "max_classification"
)
return(metrics)
}
myMetrics.LAScluster <- function(cluster)
{
las <- readLAS(cluster)
if (is.empty(las)) return(NULL)
metrics <- lasmetrics(las, ~myMetrics(las))
return(metrics)
}
opt_chunk_buffer(ctg) <- 0
opt_chunk_size(ctg) <- 0
opt_output_files(ctg) <- ""
plots_metrics <- catalog_apply(ctg, lasmetrics, func = .myMetrics(ctg))
Error in catalog_apply(las, lasmetrics, func = .myMetrics) : object '.myMetrics' not found ????
Error in catalog_apply(las, lasmetrics, func = .myMetrics) : object '.myMetrics' not found