LAZrs - LAZ Compression for Python

0.8.1 · active · verified Wed Apr 15

LAZrs provides Python bindings for `laz-rs`, a high-performance Rust implementation of LAZ (Laszip) compression and decompression. Its primary role is to serve as an optional, multi-threaded backend for other Python libraries, such as `laspy`, enabling them to efficiently read and write LAZ data. The library is currently at version 0.8.1, with releases tied to updates of its underlying Rust core.

Warnings

Install

Quickstart

LAZrs primarily functions as a high-performance backend for other libraries like `laspy`. This quickstart demonstrates how `laspy` leverages `lazrs` for transparent LAZ file compression and decompression. When `lazrs` is installed, `laspy` automatically uses it for LAZ processing, providing multi-threaded performance. There is no direct high-level API for `lazrs` for file operations; it's consumed implicitly by compatible libraries.

import laspy
import os

# Create a dummy LAS file for demonstration
header = laspy.header.Header()
header.point_format.scale = [0.01, 0.01, 0.01]
header.point_format.offset = [0, 0, 0]

points = laspy.create_points(point_count=100)
points.x = range(100)
points.y = range(100)
points.z = range(100)

input_filename = 'dummy.las'
output_filename = 'compressed.laz'

with laspy.open(input_filename, mode='w', header=header) as writer:
    writer.write_points(points)

print(f"Created {input_filename} with {points.x.shape[0]} points.")

# --- Using lazrs as a backend via laspy to compress and decompress ---
# laspy will automatically detect and use lazrs if installed.
# Explicitly set laz_backend=laspy.compression.LazBackend.Lazrs if needed.

# Compress to LAZ using lazrs (implicitly by laspy)
with laspy.open(input_filename, mode='r') as infile:
    with laspy.open(output_filename, mode='w', header=infile.header) as outfile:
        outfile.write_points(infile.read_points())

print(f"Compressed to {output_filename} using lazrs backend.")

# Decompress from LAZ using lazrs (implicitly by laspy)
with laspy.open(output_filename, mode='r') as reader:
    decompressed_points = reader.read_points()
    print(f"Decompressed {decompressed_points.x.shape[0]} points from {output_filename}.")
    assert decompressed_points.x.shape[0] == points.x.shape[0]

# Clean up dummy files
os.remove(input_filename)
os.remove(output_filename)
print("Cleaned up dummy files.")

view raw JSON →