top of page

LasPy Tutorial: Process LiDAR Point Cloud Data Step by Step in Python

  • Writer: Anvita Shrivastava
    Anvita Shrivastava
  • 6 hours ago
  • 4 min read

LiDAR (Light Detection and Ranging) is one of the most important types of geospatial technologies today. It has revolutionized the way we measure 3D space, operate autonomous vehicles, manage our forests/urban areas, and design/deliver digital elevation models. This type of technology captures millions of precise 3D points, making LiDAR one of the best remote sensing technologies available.


LasPy is an easy-to-use open-source library for working with LAS & LAZ Point Cloud files. With LasPy, you have direct access to almost all point cloud data. You have access to all point attributes: classification, point coordinates, intensity value, return value, point metadata, and point classification. LasPy performs very well while having a very simple-to-use API.


LasPy: Process LiDAR Point Cloud Data in Python
LasPy: Process LiDAR Point Cloud Data in Python

What Is LasPy?


A LAS file is an open-source file system that will help you read and write LAS and LAZ files that contain LiDAR point cloud data. Some important things you can do with LAS files include:


  • Reading LAS files and compressed LAZ files

  • Accessing the coordinates of all points in a point cloud

  • Accessing the classifications and return values associated with the points

  • Editing any attribute associated with a point

  • Writing a new LAS file with the modified point data

  • Reading and writing data to LAS Versions 1.0 through 1.4

  • Using NumPy, Pandas, GeoPandas, and Open3D


The use of NumPy Arrays to hold point data allows for the most efficient processing of millions of LiDAR point data records.


Installing LasPy


Install LasPy using pip:

pip install laspy

For LAZ file support:

pip install laspy[lazrs]

Verify installation:

import laspy

print(laspy.__version__)

Reading a LAS File


The first step in LiDAR processing is loading a LAS file.

import laspy

las = laspy.read("sample.las")

print(las)

Output:

<LasData(1.4, point fmt: 6, 1250000 points)>

This object contains both metadata and point records.


Exploring LAS Header Information


Header information provides important metadata about the dataset.

print("Version:", las.header.version)
print("Point Format:", las.header.point_format)
print("Number of Points:", las.header.point_count)

Example output:

Version: 1.4
Point Format: 6
Number of Points: 1250000

You can also inspect spatial bounds:

print("Min Coordinates:", las.header.mins)
print("Max Coordinates:", las.header.maxs)

Extracting Point Coordinates


LiDAR coordinates can be accessed directly.

x = las.x
y = las.y
z = las.z

Create a NumPy array:

import numpy as np

points = np.vstack((x, y, z)).transpose()

print(points.shape)

Output:

(1250000, 3)

Accessing Point Cloud Attributes


LasPy provides access to all stored point attributes.

print(las.point_format.dimension_names)

Common attributes:

las.intensity
las.classification
las.return_number
las.number_of_returns
las.gps_time

Example:

intensity = las.intensity

print(intensity[:10])

Understanding LiDAR Classifications


Classifications identify object types within the point cloud.

Retrieve classification values:

classification = las.classification

print(np.unique(classification))

Example output:

[1 2 3 4 5 6]

Count points per class:

unique, counts = np.unique(classification, return_counts=True)

for cls, count in zip(unique, counts):
    print(f"Class {cls}: {count}")

Filtering Ground Points


Ground extraction is one of the most common LiDAR workflows.

Classification code 2 represents ground.

ground_points = las.points[
    las.classification == 2
]

print(len(ground_points))

Create a new LAS file:

ground_las = laspy.LasData(las.header)

ground_las.points = ground_points

ground_las.write("ground_points.las")

Extracting Building Points


Building classification typically uses code 6.

building_mask = las.classification == 6

building_points = las.points[building_mask]

print(len(building_points))

Export results:

building_las = laspy.LasData(las.header)

building_las.points = building_points

building_las.write("buildings.las")

Calculating Elevation Statistics


Elevation analysis is critical in terrain modeling.

z = las.z

print("Minimum Elevation:", np.min(z))
print("Maximum Elevation:", np.max(z))
print("Mean Elevation:", np.mean(z))
print("Standard Deviation:", np.std(z))

Output:

Minimum Elevation: 155.8
Maximum Elevation: 324.2
Mean Elevation: 241.7
Standard Deviation: 22.9

Creating a Pandas DataFrame


For advanced analysis, convert point data into a DataFrame.

import pandas as pd

df = pd.DataFrame({
    "X": las.x,
    "Y": las.y,
    "Z": las.z,
    "Intensity": las.intensity,
    "Classification": las.classification
})

print(df.head())

This enables filtering, aggregation, and machine learning workflows.


Filtering by Elevation


Remove points below a threshold.

elevation_mask = las.z > 200

filtered_points = las.points[elevation_mask]

filtered_las = laspy.LasData(las.header)

filtered_las.points = filtered_points

filtered_las.write("high_elevation.las")

Working with Return Numbers


LiDAR sensors often record multiple returns.

Retrieve return information:

returns = las.return_number

print(np.unique(returns))

Filter first returns:

first_returns = las.points[
    las.return_number == 1
]

Filter last returns:

last_returns = las.points[
    las.return_number ==
    las.number_of_returns
]

These datasets are frequently used in canopy and terrain analysis.


Converting LAS Data to NumPy Arrays


Many scientific workflows require NumPy arrays.

point_array = np.column_stack(
    (las.x, las.y, las.z)
)

print(point_array.shape)

Example output:

(1250000, 3)

This format integrates seamlessly with:

  • Scikit-learn

  • Open3D

  • PyTorch

  • TensorFlow

  • SciPy


Visualizing LiDAR Point Clouds


Use Open3D for visualization.

Install:

pip install open3d

Visualization code:

import open3d as o3d
import numpy as np

points = np.column_stack(
    (las.x, las.y, las.z)
)

pcd = o3d.geometry.PointCloud()

pcd.points = o3d.utility.Vector3dVector(points)

o3d.visualization.draw_geometries([pcd])

This enables interactive 3D exploration of LiDAR datasets.


LasPy is a robust and efficient tool to handle LiDAR point clouds with Python. There are many uses for LasPy, including extracting ground point locations from point clouds, analyzing point elevation measurements, filtering and classifying LiDAR point cloud data, and preparing datasets for machine learning using LAS/LAZ formatted data files. With direct and easy access to the LAS/LAZ file structure through software processing, LasPy minimizes the difficulty associated with managing LAS/LAZ formatted files.


As developers apply techniques combining LasPy with NumPy, Pandas, GeoPandas, and Open3D, the creation of scalable pipelines for LiDAR processing is being developed at an extremely rapid pace, enabling the processing of millions of LiDAR point cloud data elements per pipeline. The increased adoption of LiDAR technologies across multiple industries, including geospatial, environmental, and autonomous, has resulted in the knowledge of LiDAR being a key area of expertise for spatial data professionals working today.


For more information or any questions regarding the LizardTech suite of products, please don't hesitate to contact us at:



USA (HQ): (720) 702–4849


(A GeoWGS84 Corp Company)



bottom of page