TransWikia.com

Getting R to recognize buffer around las file

Geographic Information Systems Asked by JessieElliott on July 16, 2021

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))

One Answer

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.

Correct answer by JRR on July 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP