Main Content

readPointCloud

Read point cloud data from LAS or LAZ file

Since R2020b

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,"Attributes",ptAtt) reads the specified point attributes ptAtt from a LAS or LAZ file. In addition to the point cloud, the function returns the specified attributes of each point in the point cloud.

example

[___] = 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.

Examples

collapse all

This example shows how to read and visualize point cloud data from a LAS / LAZ file.

Create a lasFileReader object for a LAZ file. Then, use the readPointCloud function to read point cloud data from the LAZ file and generate a pointCloud object.

Create a lasFileReader object to access the LAZ file data.

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.

Segregate and visualize point cloud data based on classification data from a LAZ file.

Create a lasFileReader object to access data from the LAZ file.

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

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

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

Color the points based on their classification attributes. Reshape the label image into the shape of the point cloud.

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

Visualize the color-coded point cloud.

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.

Point attributes, specified as a character vector, string scalar, cell array of character vectors, 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

Name-Value Arguments

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 the comma-separated pair consisting of 'ROI' and a six-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 the comma-separated pair consisting of 'GpsTimeSpan' and a two-element vector of duration objects, that denotes [startTime endTime]. The timestamps must be positive.

Data Types: duration

Classification numbers of interest, specified as the comma-separated pair consisting of 'Classification' and a vector of valid classification numbers.

Valid classification numbers range from 0 to 255.

Classification NumberClassification Type
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 and class-object mappings. 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 the comma-separated pair consisting of 'LaserReturn' and 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

Output Arguments

collapse all

Point cloud, returned as a pointCloud object.

Point attribute data, returned as a lidarPointAttributes object. The object contains data for the specified attributes ptAtt of each point in the ptCloud output.

Version History

Introduced in R2020b

expand all