2

I'm trying to test my pixel_metrics() custom function, and I'm not sure how to overwrite the old file, like the error message suggests in the screenshot. I have added overwrite=TRUE to my function call, but it doesn't seem to be working.

It seems like internally pixel_metrics() is calling writeRaster() -- maybe there is a way to propagate overwrite=TRUE to writeRaster() ?

Function call:

canopy_metrics = pixel_metrics(norm, ~lcp_pixel_metrics(Z, ReturnNumber), 16.4042, overwrite=TRUE)

Error message:

r: [writeRaster] file exists. You can use 'overwrite=TRUE' to overwrite it

In addition, I've tried running the following line of code, inspired by this post.

canopy_metrics@output_options$drivers$Raster$param$overwrite <- TRUE

But R says that "output_options" does not exist for class "SpatRaster."

1
  • I can't see anything in the help or examples about writing to a file, and I can't trigger this error from the examples, but maybe the examples are small data that can work in memory and not need to work with on-disk data... Try debug(writeRaster) and then see how its being called...
    – Spacedman
    Commented Jul 18, 2023 at 19:22

1 Answer 1

1

Your code canopy_metrics@output_options$drivers$Raster$param$overwrite <- TRUE is correct for RasterLayer from the package raster but applies to a LAScatalog. Here the default output is a SpatRaster from terra. use:

norm@output_options$drivers$SpatRaster$param$overwrite <- TRUE

2
  • I ran canopy_metrics@output_options$drivers$SpatRaster$param$overwrite <- TRUE and got the error: no slot of name "output_options" for this object of class "SpatRaster". Do you have any advice? Commented Jul 27, 2023 at 16:27
  • See my edit. This applies to a LAScatalog
    – JRR
    Commented Jul 31, 2023 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.