Skip to main content

Crate las

Crate las 

Source
Expand description

Read and write ASPRS LAS point cloud data.

§Reading

Create a Reader from a Path:

use las::Reader;
let reader = Reader::from_path("tests/data/autzen.las").unwrap();

Or anything that implements Read:

use std::io::BufReader;
use std::fs::File;
use las::Reader;
let read = BufReader::new(File::open("tests/data/autzen.las").unwrap());
let reader = Reader::new(read).unwrap();

§Prefer BufRead

Your performance will be better if your Read is actually a BufRead. Reader::from_path takes care of this for you, but Reader::new doesn’t.

§Read points

Read into a PointData and iterate with PointData::points:

use las::Reader;
let mut reader = Reader::from_path("tests/data/autzen.las").unwrap();
let pd = reader.read_all().unwrap();
for wrapped_point in pd.points() {
    let point = wrapped_point.unwrap();
    println!("Point coordinates: ({}, {}, {})", point.x, point.y, point.z);
    if let Some(color) = point.color {
        println!("Point color: red={}, green={}, blue={}",
            color.red,
            color.green,
            color.blue,
        );
    }
}

For large files that don’t fit in memory, read in chunks and reuse a PointData buffer across iterations — see Reader::read_points and Reader::fill_points.

§Writing

Create a Writer from a Write and a Header:

use std::io::Cursor;
use las::{Writer, Header};
let write = Cursor::new(Vec::new());
let header = Header::default();
let writer = Writer::new(write, header).unwrap();

You can also write out to a path (automatically buffered with BufWriter):

use las::Writer;
let writer = Writer::from_path("/dev/null", Default::default());

Use a Builder to customize the las data:

use std::io::Cursor;
use las::{Writer, Builder};
use las::point::Format;

let mut builder = Builder::from((1, 4));
builder.point_format = Format::new(2).unwrap();
let header = builder.into_header().unwrap();

let write = Cursor::new(Vec::new());
let writer = Writer::new(write, header).unwrap();

§Prefer BufWriter

Just like the Reader, your performance will improve greatly if you use a BufWriter instead of just a Write.

§Write points

Write points one at a time:

use std::io::Cursor;
use las::{Writer, Point};
let mut writer = Writer::default();
let point = Point { x: 1., y: 2., z: 3., ..Default::default() };
writer.write_point(point).unwrap();

§Compression

The laz compression format is the de-facto standard for compression las data. To enable laz support, enable the laz or laz-parallel feature:

[dependencies]
las = { version = "0.9", features = ["laz"] }  # or laz-parallel

Then, you can compress the data when writing:

use std::io::Cursor;
use las::{Writer, Builder};
use las::point::Format;

let mut builder = Builder::from((1, 4));
builder.point_format = Format::new(2).unwrap();
builder.point_format.is_compressed = true;
let header = builder.into_header().unwrap();
let write = Cursor::new(Vec::new());
let result =  Writer::new(write, header);
if cfg!(feature = "laz") {
    assert!(result.is_ok());
} else {
    assert!(result.is_err());
}

Writer::from_path will use the extension of the output file to determine wether the data should be compressed or not:

  • .laz: compressed
  • .las: not compressed

Re-exports§

pub use crate::copc::CopcEntryReader;
pub use crate::feature::Feature;
pub use crate::header::Builder;
pub use crate::header::Header;
pub use crate::point::Point;
pub use crate::reader::Reader;
pub use crate::reader::ReaderOptions;
pub use crate::vlr::Vlr;
pub use crate::writer::Writer;
pub use crate::writer::WriterOptions;
pub use reader::LazParallelism;

Modules§

copc
COPC header data
crs
Module for handling Coordinate Reference System (CRS) data in a headers variable length records
feature
Programmatically determine whether a las version supports a feature.
header
A Header describes the configuration and properties of las data.
laz
Utility functions for working with laszip compressed data.
point
Attributed three-dimensional points.
raw
Raw structures that map directly to their definitions in the las format specifications.
reader
Read las points.
vlr
Variable length records are used to store additional metadata not defined in the header.
writer
Write las points.

Structs§

Bounds
Minimum and maximum bounds in three dimensions.
Color
A RGB color value.
PointData
A set of decompressed LAS point records held as one contiguous byte slab.
PointDataBuilder
Builder for PointData.
PointDataIter
Iterator over points in a PointData, yielding owned Point values.
Transform
A scale and an offset that transforms xyz coordinates.
Vector
An xyz collection.
Version
LAS version.

Enums§

Error
Crate-specific error enum.
GpsTimeType
The meaning of GPS time in the point records.

Type Aliases§

Result
Crate-specific result type.