1

Using lidR 3.1.3, is it possible to classify points inside polygons shapefile for a LASCatalog, something like the previous lasclassify() function. I'm looking for a equivalent of this PDAL method.

ctg <- lidR::readLAScatalog(path_to_folder)
shapefile = rgdal::readOGR(shapefile_file)
opt_output_files(ctg) <- paste0(path_to_folder, "/{ORIGINALFILENAME}_classified")

# Need to classify here
output<- classify_within_polygons(ctg, shapefile)
3
  • Are you looking for the clip_roi() function?
    – JRR
    Commented Mar 16, 2021 at 10:05
  • The opposite : get only points outside the geometry
    – juu
    Commented Mar 16, 2021 at 10:24
  • Please edit your question to clarify your wish an try to provide a base of code we can use or at least an picture of what you want. Otherwise your question is likely to get closed for not being clear enough.
    – JRR
    Commented Mar 16, 2021 at 10:30

1 Answer 1

2

With a loaded point-cloud (LAS) you can use merge_spatial(). Lets load some data first:

library(lidR)
library(sf)

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
shp <- system.file("extdata", "lake_polygons_UTM17.shp", package = "lidR")
las <- readLAS(LASfile)
poly <- st_read(shp, quiet = TRUE)
plot(las@header)
plot(poly, add = TRUE)

We can now use merge_spatial() to know if points are in or out the polygon(s). Then we can use this information to clip or classify.

las <- merge_spatial(las, poly, "inpoly")
las$Classification[las$inpoly == TRUE] <- LASWATER
las$Classification[las$inpoly == FALSE & las$Classification != LASGROUND] <- LASLOWVEGETATION
plot(las, color = "Classification")

veg = filter_poi(las, inpoly == FALSE)
plot(veg)

However it is not possible (yet) to directly classify the point-cloud from a LAScatalog. You must build your own tools based on this answer and catalog_apply()

1
  • I didn't know merge_spatial(), it works perfectly. Thanks for the clear answer and examples.
    – juu
    Commented Mar 16, 2021 at 11:17

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.