I'm trying to modify/update the code in this answer (Partially processing a catalog with an extent in lidR), in order to partially process a catalog with a polygon (e.g., to pick up after a computer crash):
library(lidR)
ctg <- readLAScatalog("D:/Project2024_0507")
aoi <- read_sf(dsn = "D:/Project2024_0507",
layer = "toDo_May16",
quiet = TRUE,
stringsAsFactors = FALSE,
as_tibble = TRUE)
aoisp <- sf::as_Spatial(aoi)
spctg <- as.spatial(ctg)
ctg$processed <- T
ctg$processed <- sf::st_intersection(aoisp, spctg)
Both aoisp and spctg are class SpatialPolygonsDataFrame. But st_intersection gives me an error (no applicable method).
Additionally, st_intersection doesn't allow for extracting the id necessary for $processed.