Learn R Programming

lidR (version 1.6.1)

lasclip: Clip LiDAR points

Description

Clip LiDAR points within a given geometry from a point cloud (LAS object) or a catalog (LAScatalog object)

Usage

lasclip(x, geometry, ofile = "", inside = TRUE, ...)

lasclipRectangle(x, xleft, ybottom, xright, ytop, ofile = "", inside = TRUE, ...)

lasclipPolygon(x, xpoly, ypoly, ofile = "", inside = TRUE, ...)

lasclipCircle(x, xcenter, ycenter, radius, ofile = "", inside = TRUE, ...)

Arguments

x

An object of class LAS or LAScatalog.

geometry

a geometric object. Currently Polygon and SpatialPolygonsDataFrame from sp are supported.

ofile

character. Path to an output file (only with a LAScatalog object). If ofile = "" the result is loaded into R, otherwise the result is written to a file while reading. This is much more memory-efficient than loading into R first, then writing.

inside

logical. Inverts the selection (only with a LAS object). Select inside or outside the shape.

...

Additional argument for readLAS to reduce the amount of data loaded (only with a LAScatalog object)

xleft

scalar of left x position of rectangle.

ybottom

scalar of bottom y position of rectangle.

xright

scalar of right x position of rectangle.

ytop

scalar of top y position of rectangle.

xpoly

numerical array. x-coordinates of polygon.

ypoly

numerical array. y-coordinates of polygon.

xcenter

scalar of x disc center.

ycenter

scalar of y disc center.

radius

scalar of disc radius.

Value

An object of class LAS or NULL if the result is immediately written to a file.

Details

lasclip functions work both on LAS and LAScatalog objects. With a LAS object, the user first reads and loads a point-cloud and then clip it to get a subset within a region of interest (ROI). With a LAScatalog object, the user extracts the ROI without loading the whole point-cloud. This is faster and much more memory-efficient for extracting ROIs.

Minor differences exist between the LAS and LAScatalog version of lasclip. For example the user can clip a SpatialPolygonsDataFrame from a LAS object but not from a LAScatalog. Also the option inside = FALSE is disabled for LAScatalog objects. These differences are generally justified by memory safety concerns.

Examples

Run this code
# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")

# Load the file and clip the region of interest
las = readLAS(LASfile)
subset1 = lasclipRectangle(las, 684850, 5017850, 684900, 5017900)

# Do not load the file, extract only the region of interest
ctg = catalog(LASfile)
subset2 = lasclipRectangle(ctg, 684850, 5017850, 684900, 5017900)

# Extract a polygon from a shapefile
shapefile_dir <- system.file("extdata", package = "lidR")
lakes = rgdal::readOGR(shapefile_dir, "lake_polygons_UTM17")
lake = lakes@polygons[[1]]@Polygons[[1]]
subset3 = lasclip(ctg, lake)

# Extract a polygon, write it in a file, do not load anything in R
file = paste0(tempfile(), ".las")
lasclip(ctg, lake, ofile = file)

# }
# NOT RUN {
plot(subset1)
plot(subset2)
plot(subset3)
# }

Run the code above in your browser using DataLab