I have clipped a point cloud with a shapefile containing multiple polygons, using clip_roi() function. The result is a list of LAS files. However, when I try to loop through the list and save each individual file, I get Error: Argument is not a LAS object. Here is the code:

las = readLAS("plot_a3.las", filter = "-drop_z_below 0")
polys = shapefile("plot_a_segments.shp")
clipped = clip_roi(las, polys)

for (i in range(lengths(clipped))) 
  file <-file.path('Plot_A', paste0('plot_a_', clipped[i], '.las'))
  writeLAS(clipped[i], file, index = FALSE)

How do I correctly save the output so that each clipped point cloud is saved as a separate LAS file?

1 Answer 1


clipped[i] returns a list with one element. You meant clipped[[i]] with double brackets. Also clipped[i] within paste0() is meaningless.

Actually your use case is already covered by the package. Assuming that your shapefile has an attribute PLOTID (replace with something else if needed)

ctg <- readLAScatalog("folder/plot_a3.las", filter = "-drop_z_below 0")
polys <- shapefile("folder/plot_a_segments.shp")

opt_output_files(ctg) <- "folder/plot_a_{PLOTID}"
new_ctg <- clip_roi(ctg, polys)

If you don't have any unique ID in the shapefile you can generate other filename patterns with {XCENTER}, {YCENTER}, {ID} and so on. See the documentation


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.