3

I'm trying to clip from a catalog using a shapefile. The file is huge, so I've divided it into two (ctgw1 and ctgw2). The final radius should be 47 (the ctg is in feet) and I'm trying to set a buffer of 328ft (100m). This all runs fine and creates valid las files, but when I run it, I receive the error code:

ERROR buffer greater than 0 is needed

ctg <- catalog(folder = "D:/All LAS")
shp.w <-shapefile("C:/Users/elliot59/Downloads/plot4w/plot4w.shp") 

bufferw <- lasclip(ctg, shp.w, radius = 328.084)

plots <- seq(1:244)
for(n in 1:length(plots)){
  plot.n <- plots[n]
  if(bufferw[[plot.n]]@header@PHB$`Number of point records` == 0) { 
    next
  }
  writeLAS(bufferw[[plot.n]], file = paste('plot', plot.n, ".las", sep = ""))
}
ctgw1 <- catalog(folder = "C:/Users/elliot59/Desktop/buffer.w1")
ctgw2 <- catalog(folder = "C:/Users/elliot59/Desktop/buffer.w2")

opt_output_files(ctgw1) <- ("C:/Users/elliot59/Desktop/Out")
opt_laz_compression(ctgw1) <- TRUE

thinnedctgw <- lasfilterdecimate(ctgw1, random(2))

dtm <- grid_terrain(thinnedctgw, 1, kriging(k = 10L))

1 Answer 1

4

First you almost never need to write your own loop in lidR. Your plot extraction becomes.

ctg <- catalog(folder = "D:/All LAS")
shp.w <-shapefile("plot4w.shp")
opt_output_files(ctg) <- "plot_{ID}"
ctgw1 <- clip_roi(ctg, shp.w, radius = 328)

This is much more efficient because your 244 plots are never loaded in R. They are streamed from input to output files. At this stage ctgw1 is a collection of 244 non-contiguous files

The line

opt_output_files(ctgw1) <- ("C:/Users/elliot59/Desktop/Out")

is incorrect but I already explained you that in a previous question.

Then you try to create a DTM from discontinuous plots. I understand that you want 47 ft plots but you extracted 328 ft plots to get a buffer. This is good. grid_terrain() is designed to guarantee a strict wall-to-wall output this is why a buffer is mandatory but in your case it is meaningless. You can disable the wall-to-wall guaranties

opt_chunk_size(ctw1) <- 0
opt_wall_to_wall(ctgw1) <- FALSE
opt_output_file(ctgw1) <- "DTM_{*}"
dtm <- grid_terrain(thinnedctgw, 1, kriging(k = 10L))

But this will create a very big virtual raster mostly empty. The point here is that you want to process by file, without buffer, without generating a continuous DTM. You can use a regular for loop.

5
  • Thank you so much for your time and patience! This worked for the dtm! The only problem is that I'm encountering an error "filename exists; use overwrite=TRUE" when I try to make a chm. I cannot find the function "overwrite". norma <- lasnormalize(ctgw1, res = 1.5, algorithm = tin()) chm <- grid_canopy(norma, res = 1.5, p2r()) Commented May 14, 2020 at 17:26
  • 1
    see gis.stackexchange.com/questions/325367/…
    – JRR
    Commented May 14, 2020 at 18:18
  • Thank you very much JRR! This worked for the overwrite. I am currently having trouble with chm reading in as a collection of .tif files but will continue to troubleshoot Commented May 14, 2020 at 19:03
  • My chm will not plot and seems to be a collection of 237 .tif files. > summary(chm) Length Class Mode 237 character character Is this normal or how can I correct it? Commented May 14, 2020 at 20:59
  • 1
    Ask a question with reproducible example.
    – JRR
    Commented May 14, 2020 at 22:49

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.