I'm tryin to clip multiple AOIs from a Lascatalog using a dataframe containing centres and radii of various plots.
I can probably loop through the data frame and use lasclipCircle() to clip each plot and write it. I was wondering if there is a more efficient way to simultaneously do this while retaining the plot ID (from the dataframe) for each file, if possible.
Answer
The documentation of lasclipCircle() states that you can input multiple coordinates (plural is used)
xcenternumeric. x coordinates of discs centers.
ycenternumeric. y coordinates of discs centers.
radiusnumeric. disc radius or radii.
So it works as you may expect
ctg = readLAScatalog(...)
p = read.table(...)
aois = lasclipCircle(ctg, p$x, p$y, p$radius) # AOIs is a list of LAS
The output is a list of LAS object so you can rename it with you AOIs IDs if you want. And you automatically get access to all the feature of the LAScatalog processing engine so the following works to write your AOIs on files (see the documentation of the engine ?lidR::LAScatalog-class)
opt_filter(ctg) <- "-keep_first"
opt_output_file <- "/folder/AOI_{ID}"
aois = lasclipCircle(ctg, p$x, p$y, 10) # aois is a LAScatalog
You can also find a solution using lasclip() with a shapefile here to preserve attributes with filenames. Something like that will work:
coordinates(p) <- ~x+y # cast to SpatialPointsDataFrame
opt_filter(ctg) <- "-keep_first"
opt_output_file <- "/folder/AOI_{AOIID}" # If AOIID is the name of a column
aois = lasclip(ctg, p, radius = 10)
No comments:
Post a Comment