Geographic Information Systems Asked by Aleksandra Zaforemska on September 30, 2021
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?
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
Correct answer by JRR on September 30, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP