Perfect answer by @andre-silva but let met add few informations. In lidR 1.5.0
you will be able to clip using a SpatialPolygonDataFrame
. In that case you will get a list
of LAS objects (one per polygon).
las = readLAS("file.las")
spdf <- readOGR(dsn = "...", layer = "...")
clipped_las = lasclip(ctg, spdf)
Also lasclip
will be compatible with a LAScatalog
. You don't need anymore to load the entire tile to extract a single polygon. Just extract the polygon.
ctg = catalog("directory/")
spdf <- readOGR(dsn = "...", layer = "...")
poly <- spdf@polygons[[1]]@Polygons[[1]] # sp object of class Polygon
clipped_las = lasclip(ctg, poly)
But be careful. You can't clip a SpatialPolygonDataFrame
from a LAScatalog
. It is technically possible but it has been disabled for two reasons. The first one is memory safety. Indeed, assuming you have 1000 tiles over 1000 km² and a shapefile with hundreds of large polygons, this would load too much data. In order to prevent R crash with bad usage this option is disabled. The second reason is multipart polygons
Regarding multipart polygons, the rlas
package only supports single polygon extraction. Thus it is extremely easy to efficiently extract a SpatialPolygon
. For SpatialPolygons
(potentially multipart polygons with holes) this is not currently natively supported. It requires more computation that are not memory efficient. This is why it is not supported yet but this will be added in lidR
later.