merge_spatial {lidR}R Documentation

Merge a point cloud with a source of spatial data

Description

Merge a point cloud with a source of spatial data. It adds an attribute along each point based on a value found in the spatial data. Sources of spatial data can be a ⁠SpatialPolygons*⁠, an sf/sfc, a ⁠Raster*⁠, a stars, or a SpatRaster.

Usage

merge_spatial(las, source, attribute = NULL)

Arguments

las

An object of class LAS

source

An object of class ⁠SpatialPolygons*⁠ or sf or sfc or RasterLayer or RasterStack or RasterBrick or stars.

attribute

character. The name of an attribute in the table of attributes or the name of a new column in the LAS object. Not relevant for RGB colorization.

Value

a LAS object

Examples

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
shp     <- system.file("extdata", "lake_polygons_UTM17.shp", package = "lidR")

las   <- readLAS(LASfile, filter = "-keep_random_fraction 0.1")
lakes <- sf::st_read(shp, quiet = TRUE)

# The attribute "inlake" does not exist in the shapefile.
# Points are classified as TRUE if in a polygon
las    <- merge_spatial(las, lakes, "inlakes")     # New attribute 'inlakes' is added.
names(las)

forest <- filter_poi(las, inlakes == FALSE)
#plot(forest)

# The attribute "LAKENAME_1" exists in the shapefile.
# Points are classified with the values of the polygons
las <- merge_spatial(las, lakes, "LAKENAME_1")     # New column 'LAKENAME_1' is added.
names(las)

[Package lidR version 4.1.2 Index]