LASzip Python Bindings

0.3.0 · active · verified Thu Apr 16

The `laszip` library provides Python bindings for the LASzip C/C++ library, enabling efficient compression and decompression of LAZ (compressed LAS) point cloud files. It leverages `pybind11` for seamless integration. The current version is 0.3.0, and releases occur as needed for bug fixes and feature enhancements, typical for a pre-1.0 library.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a minimal LAZ file with a single point and then read it back using `laszip.LaszipWriter` and `laszip.LaszipReader`. It sets up a temporary file to ensure the example is runnable without pre-existing data.

import laszip
import os
import tempfile

# Create a temporary file path
temp_laz_path = os.path.join(tempfile.gettempdir(), "test_laszip_quickstart.laz")

try:
    # 1. Prepare a minimal header for writing
    header = laszip.LaszipHeader()
    header.major_version = 1
    header.minor_version = 4
    header.point_data_format = 6  # Standard LAS 1.4, Point Data Record Format 6
    header.point_data_record_length = 36 # bytes for format 6
    header.number_of_point_records = 1
    header.X_offset = 0.0; header.Y_offset = 0.0; header.Z_offset = 0.0
    header.X_scale_factor = 0.01; header.Y_scale_factor = 0.01; header.Z_scale_factor = 0.01
    header.min_x = 100.0; header.max_x = 100.0
    header.min_y = 200.0; header.max_y = 200.0
    header.min_z = 300.0; header.max_z = 300.0

    # Prepare a dummy point
    point = laszip.LaszipPoint()
    point.X = 10000; point.Y = 20000; point.Z = 30000 # Scaled by 0.01
    point.classification = 1
    point.intensity = 100

    # 2. Write a dummy LAZ file
    print(f"Writing dummy LAZ to {temp_laz_path}")
    with laszip.LaszipWriter(temp_laz_path, header_in=header) as writer:
        writer.write_point(point)

    # 3. Read the LAZ file back
    print(f"Reading from {temp_laz_path}")
    with laszip.LaszipReader(temp_laz_path) as reader:
        read_header = reader.header
        print(f"  Read header - Point count: {read_header.number_of_point_records}")
        read_point = reader.read_point()
        print(f"  Read point: X={read_point.X}, Y={read_point.Y}, Z={read_point.Z}")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # 4. Clean up the temporary file
    if os.path.exists(temp_laz_path):
        os.remove(temp_laz_path)
        print(f"Cleaned up {temp_laz_path}")

view raw JSON →