gadomski / las-rs

Read and write ASPRS las files, Rust edition.
MIT License
73 stars 32 forks source link

header.point_format() is buggy for LAZ #27

Closed hugoledoux closed 4 years ago

hugoledoux commented 4 years ago

Same file in LAS and LAZ gives different answers; LAS is correct, LAZ obviously wrong since format>10.

Not sure if this is a bug here or for https://github.com/tmontaigu/laz-rs?

use las::{Read, Reader};
fn main() {
    let mut rs = Reader::from_path("/Users/hugo/data/ahn3/crop.las").unwrap();
    let mut rz = Reader::from_path("/Users/hugo/data/ahn3/crop.laz").unwrap();
    let pfs: u8 = rs.header().point_format().to_u8().unwrap();
    let pfz: u8 = rz.header().point_format().to_u8().unwrap();
    println!("=>{}", pfs);
    println!("=>{}", pfz);
}

=> 1 => 129

tmontaigu commented 4 years ago

The bug is in las-rs,

For LAZ files, laszip sets the most significant bit of the point format to 1 in the header to indicate compressed data, so for point format 1 the point format id becomes 1000_0001 (129) when it's a LAZ file.

The problem here is that in las-rs we return this compressed point format id in the public interface instead of returning the proper id and keeping the compressed fmt id internally only