Skip to main content
deleted 149 characters in body
Source Link
JRR
  • 9.7k
  • 1
  • 14
  • 29

There are several confusion in your example. You tried to use the "metrics syntax" (if I can called it this way) in a wrong way. When defining a "metric" function the input should be some attributes of a LAS object. It is hard to me to evaluate which part of the documentation you misunderstood so below a workable example. Do not hesitate to ask for more details.

Also you noticed that lasmetrics can be used in catalog_apply. This is a special case actually. To give you a full anwseranswer you could have used the following syntax (you were actually close)

There are several confusion in your example. You tried to use the "metrics syntax" (if I can called it this way) in a wrong way. When defining a "metric" function the input should be some attributes of a LAS object. It is hard to me to evaluate which part of the documentation you misunderstood so below a workable example. Do not hesitate to ask for more details.

Also you noticed that lasmetrics can be used in catalog_apply. This is a special case actually. To give you a full anwser you could have used the following syntax (you were actually close)

There are several confusion in your example. You tried to use the "metrics syntax" (if I can called it this way) in a wrong way. When defining a "metric" function the input should be some attributes of a LAS object.

Also you noticed that lasmetrics can be used in catalog_apply. This is a special case actually. To give you a full answer you could have used the following syntax (you were actually close)

deleted 1 character in body
Source Link
JRR
  • 9.7k
  • 1
  • 14
  • 29

Also you noticed that lasmetrics can be used in catalog_apply. This is a special case actually. To give you a full anwser you could have used the following syntax (youryou were actually close)

Also you noticed that lasmetrics can be used in catalog_apply. This is a special case actually. To give you a full anwser you could have used the following syntax (your were actually close)

Also you noticed that lasmetrics can be used in catalog_apply. This is a special case actually. To give you a full anwser you could have used the following syntax (you were actually close)

added 59 characters in body
Source Link
JRR
  • 9.7k
  • 1
  • 14
  • 29
myMetrics <- function(x,y,z,cl) 
{
  metrics <- list(
    min_x <- min(x),
    max_x <- max(x),
    min_y <- min(y),
    max_y <- max(y),
    min_z <- min(z),
    max_z <- max(z),
    min_classification <- min(cl),
    max_classification <- max(cl))
  names(metrics) <- c("min_x", "max_x", "min_y", "max_y", "min_z", "max_z", "min_classification", "max_classification")
  return(metrics)
}

library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
ctg = readLAScatalog(LASfile)

opt_chunk_buffer(ctg) <- 0
opt_chunk_size(ctg) <- 0
opt_output_files(ctg) <- ""

# lasmetrics supports to be used in catalog_apply.
plots_metrics <- catalog_apply(ctg, lasmetrics, func = ~myMetrics(X,Y,Z,Classification))
plots_metrics <- data.table::rbindlist(plots_metrics)

That being said your "metrics" are not really useful here. Your are processing by file so you are trying to get the bounding box of each file. The bounding box is already given in the header of the files. You can have an immediate access to them (assuming the LAS file isfiles are valid).

myMetrics <- function(x,y,z,cl) 
{
  metrics <- list(
    min_x <- min(x),
    max_x <- max(x),
    min_y <- min(y),
    max_y <- max(y),
    min_z <- min(z),
    max_z <- max(z),
    min_classification <- min(cl),
    max_classification <- max(cl))
  names(metrics) <- c("min_x", "max_x", "min_y", "max_y", "min_z", "max_z", "min_classification", "max_classification")
  return(metrics)
}

library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
ctg = readLAScatalog(LASfile)

opt_chunk_buffer(ctg) <- 0
opt_chunk_size(ctg) <- 0
opt_output_files(ctg) <- ""

# lasmetrics supports to be used in catalog_apply.
plots_metrics <- catalog_apply(ctg, lasmetrics, func = ~myMetrics(X,Y,Z,Classification))

That being said your "metrics" are not really useful here. Your are processing by file so you are trying to get the bounding box of each file. The bounding box is already given in the header of the files. You can have an immediate access to them (assuming the LAS file is valid).

myMetrics <- function(x,y,z,cl) 
{
  metrics <- list(
    min_x <- min(x),
    max_x <- max(x),
    min_y <- min(y),
    max_y <- max(y),
    min_z <- min(z),
    max_z <- max(z),
    min_classification <- min(cl),
    max_classification <- max(cl))
  names(metrics) <- c("min_x", "max_x", "min_y", "max_y", "min_z", "max_z", "min_classification", "max_classification")
  return(metrics)
}

library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
ctg = readLAScatalog(LASfile)

opt_chunk_buffer(ctg) <- 0
opt_chunk_size(ctg) <- 0
opt_output_files(ctg) <- ""

# lasmetrics supports to be used in catalog_apply.
plots_metrics <- catalog_apply(ctg, lasmetrics, func = ~myMetrics(X,Y,Z,Classification))
plots_metrics <- data.table::rbindlist(plots_metrics)

That being said your "metrics" are not really useful here. Your are processing by file so you are trying to get the bounding box of each file. The bounding box is already given in the header of the files. You can have an immediate access to them (assuming the LAS files are valid).

added 57 characters in body
Source Link
JRR
  • 9.7k
  • 1
  • 14
  • 29
Loading
added 57 characters in body
Source Link
JRR
  • 9.7k
  • 1
  • 14
  • 29
Loading
Source Link
JRR
  • 9.7k
  • 1
  • 14
  • 29
Loading