Main Content

readPointCloud

Read point cloud data from LAS or LAZ file

Description

ptCloud = readPointCloud(lasReader) reads the point cloud data from the LAS or LAZ file indicated by the input lasFileReader object and returns it as a pointCloud object, ptCloud.

example

[ptCloud,ptAttributes] = readPointCloud(lasReader) additionally returns a lidarPointAttributes object, ptAttributes, which contains all available point attributes in the input LAS or LAZ file. (since R2025a)

[___] = readPointCloud(___,Name=Value) specifies options using one or more name-value pair arguments in addition to any of the argument combinations in previous syntaxes. For example, "ROI",[5 10 5 10 5 10] sets the region of interest (ROI) in which the function reads the point cloud.

example

Examples

collapse all

Create a lasFileReader object to use to read point cloud data and header information from a LAZ file.

filepath = fullfile(toolboxdir("lidar"),"lidardata", ...
    "las","aerialLidarData.laz");
lasReader = lasFileReader(filepath);

Read point cloud data from the LAZ file using the readPointCloud function.

ptCloud = readPointCloud(lasReader);

Visualize the point cloud.

figure
pcshow(ptCloud.Location)

Figure contains an axes object. The axes object contains an object of type scatter.

Create a lasFileReader object to use to read point cloud data and header information from a LAZ file.

path = fullfile(toolboxdir("lidar"),"lidardata", ...
    "las","aerialLidarData.laz");
lasReader = lasFileReader(path);

Read point cloud data and classification attributes from the LAZ file using the readPointCloud function.

[ptCloud,pointAttributes] = readPointCloud(lasReader,Attributes="Classification");

Convert classification labels to RGB colors, and reshape them to match the point cloud structure.

labels = label2rgb(pointAttributes.Classification);
colorData = reshape(labels,[],3);

Visualize the point cloud using the color information.

figure
pcshow(ptCloud.Location,colorData)

Figure contains an axes object. The axes object contains an object of type scatter.

Input Arguments

collapse all

LAS or LAZ file reader, specified as a lasFileReader object.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: "ROI",[5 10 5 10 5 10] sets the region of interest (ROI) in which the function reads the point cloud.

ROI to read in the point cloud, specified as a 6-element row vector in the order, [xmin xmax ymin ymax zmin zmax]. Each element must be a real number. The values specify the ROI boundaries in the x-, y-, and z-axis.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Range of GPS timestamps, specified as a 2-element vector of duration objects, that denotes [startTime endTime]. The timestamps must be positive.

Data Types: duration

Classification value, specified as a vector of valid classification numbers.

Valid classification numbers range from 0 to 255.

Classification ValueClass Name
0Created, never classified
1Unclassified
2Ground
3Low vegetation
4Medium vegetation
5High vegetation
6Building
7Low point (noise)
8Reserved
9Water
10Rail
11Road surface
12Reserved
13Wire guard (shield)
14Wire conductor (phase)
15Transmission tower
16Wire-structure connector (insulator)
17Bridge deck
18High noise
19 Overhead structure
20Ignored ground
21Snow
22Temporal exclusion
23- 63Reserved
64 - 255User-defined

These are standard class names. The class definition and mapping might differ from the standard depending on the application that created the LAS or LAZ file.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of points segregated by their return numbers, specified as a vector of valid return numbers. Valid return numbers are integers from 1 to the value of the NumReturns property of the input lasFileReader object. For each value, i, in the vector, the function returns a point cloud of only the points that have i as their return number.

The return number is the number of times a laser pulse reflects back to the sensor.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Point attributes, specified as a character vector, cell array of character vectors, string scalar, or vector of strings. The input must contain one or more of these options:

  • "Classification"

  • "GPSTimeStamp"

  • "LaserReturn"

  • "NumReturns"

  • "NearIR"

  • "ScanAngle"

  • "UserData"

  • "PointSourceID"

  • "ScannerChannel"

  • "ScanDirectionFlag"

  • "EdgeOfFlightLineFlag"

  • "WaveformData"

The function returns the specified attributes of each point in a lidarPointAttributes object, ptAttributes. The unspecified attributes are returned empty.

Data Types: char | string | cell

Output Arguments

collapse all

Point cloud, returned as a pointCloud object.

Note

Point cloud functions expect data in Cartesian coordinates, (x,y,z) as positions in a 3-D coordinate space. If a LAS or LAZ file contains data in geographic coordinates, (longitude,latitude,height), you must convert the data to Cartesian coordinates. For more information on how to check and convert point cloud data from geographic to Cartesian coordinates, see the Working with Geographic CRS section of the Visualize Point Clouds on Maps Using Coordinate Reference System from LAS/LAZ Files example.

Point attribute data, returned as a lidarPointAttributes object. By default, the object returns all attributes available in the input LAS or LAZ file for each point in the point cloud. However, if you specify the Attributes name-value argument, the object returns only the specified attributes and provides empty data for any unspecified attributes.

Version History

Introduced in R2020b

expand all