2

I have a catalog of just over 3000 LAZ files that I want to split into regions using clip_rectangle(). The total catalog size is 60GB. My PC has 64GB of RAM but I get an error that lidR is unable to create a 2.8GB vector when I try to create my subset.

Is the simple answer to get more RAM or is there a way to avoid this without having to add more RAM?

Here's my script:

library(lidR)
set_lidr_threads(6L)
ctg <- readLAScatalog("c:/noaa/utm/ground/")
#Make sure we plot the catalog so we can see where we want our clip regions
plot(ctg)
subset = clip_rectangle(ctg, 5550000, 2795000,570000,27972500)

enter image description here

2 Answers 2

2

clip_rectangle() extracts the region of interest as a single point-cloud. Here you are trying to load something like 100 files in R. For sure it failed and more RAM won't help. You are better to subset the LAScatalog with catalog_intersect().

subset = catalog_intersect(ctg, raster(extent(5550000, 2795000,570000,27972500)))
4
  • No matter what values I use for the extents, I get the following error: Error in slot(y, "proj4string") : no slot of name "proj4string" for this object of class "Extent"
    – Steve
    Commented Mar 28, 2021 at 2:15
  • Try with a raster. I edited my anwser
    – JRR
    Commented Mar 28, 2021 at 9:58
  • That seems to work although I get a warning message about Non Identical CRS
    – Steve
    Commented Mar 28, 2021 at 21:25
  • Yes indeed but it does not really matter here
    – JRR
    Commented Mar 28, 2021 at 22:31
0

You can return a new catalog representing the results of the manipulation, if you first define a new disk directory for catalog output files:

lidR::opt_output_files(full_catalog) <- "/path/to/your/NEW_catalog/"

When you perform the processing (small_catalog <- clip_rectangle(full_catalog, ...)), instead of returning the clipping results to memory, it saves them do a disk, builds a new catalog out of them, and returns the new catalog to R environment to be used later.

After the operation, remember to set the output file location to null with lidR::opt_output_files(full_catalog) <- "" if you do not want to save also later operations on this full catalog to the new catalog directory.

It might also be that the newly created catalog inherits the options from the source catalog. I would perform the same operation to the clipped catalog. lidR::opt:output_files(small_catalog) <- "" This way the results are returned directly to R as LAS-objects, without saving them to a disk and returning a corresponding catalog.

From the official documentation:

The slot ⁠@output_options⁠ contains a list of options that determine how chunks (the sub-areas that are sequentially processed) are written. By "written" we mean written to files or written in R memory.

output_files: string. If output_files = "" outputs are returned in R. Otherwise, if output_files is a string the outputs will be written to files. This is useful if the output is too big to be returned in R. A path to a filename template without a file extension (the engine guesses it for you) is expected. When several files are going to be written a single string is provided with a template that is automatically filled. For example, the following file names are possible:

"/home/user/als/normalized/file_{ID}segmented" "C:/user/document/als/zone52{XLEFT}_{YBOTTOM}_confidential" "C:/user/document/als/{ORIGINALFILNAME}_normalized"

This option will generate as many filenames as needed with custom names for each file. The allowed templates are {XLEFT}, {XRIGHT}, {YBOTTOM}, {YTOP}, {ID}, {XCENTER}, {YCENTER}, {ORIGNALFILENAME}. See opt_output_files.

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.