Learn R Programming

lidR (version 2.1.4)

lasmergespatial: 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 SpatialPolygonsDataFrame) or a RasterLayer.

  • SpatialPolygonsDataFrame: it checks if the points belongs within each polygon. If the parameter attribute is the name of an attribute in the table of attributes of the shapefile, it assigns to the points the values of that attribute. Otherwise it classifies the points as boolean. TRUE if the points are in a polygon, FALSE otherwise.

  • RasterLayer: it attributes to each point the value found in each pixel of the RasterLayer.

  • RasterStack or RasterBrick must have 3 channels for RGB colors. It colorizes the point cloud with RGB values.

Usage

lasmergespatial(las, source, attribute = NULL)

Arguments

las

An object of class LAS

source

An object of class SpatialPolygonsDataFrame or RasterLayer or a RasterStack or RasterBrick with RGB colors.

attribute

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

Value

An object of the class LAS.

Examples

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

las   <- readLAS(LASfile)
lakes <- shapefile(shp)

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

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

Run the code above in your browser using DataLab