Skip to content

Commit

Permalink
Ignore point padding for compressed files
Browse files Browse the repository at this point in the history
Ignores any potential point padding between the end of the point data and the start of the first elvr if the point format is compressed.

Closes #39
  • Loading branch information
jshrake authored and gadomski committed May 6, 2024
1 parent 8d47577 commit db6cc85
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/reader.rs
Expand Up @@ -265,18 +265,33 @@ impl<'a> Reader<'a> {

read.seek(SeekFrom::Start(offset_to_end_of_points))?;
if let Some(evlr) = evlr {
match evlr.start_of_first_evlr.cmp(&offset_to_end_of_points) {
Ordering::Less => {
return Err(Error::OffsetToEvlrsTooSmall(evlr.start_of_first_evlr).into())
}
Ordering::Equal => {} // pass
Ordering::Greater => {
let n = evlr.start_of_first_evlr - offset_to_end_of_points;
read.by_ref()
.take(n)
.read_to_end(&mut builder.point_padding)?;
// Account for any padding between the end of the point data and the start of the ELVRs
//
// Ignore this case if the point format is compressed.
// See https://github.com/gadomski/las-rs/issues/39
//
// When reading a compressed file, evlr.start_of_first_evlr
// is a compressed byte offset, while offset_to_end_of_points
// is an uncompressed byte offset, which results in
// evlr.start_of_first_evlr < offset_to_end_of_points,
//
// In this case, we assume that the ELVRs follow the point
// record data directly and there is no point_padding to account for.
if !builder.point_format.is_compressed {
match evlr.start_of_first_evlr.cmp(&offset_to_end_of_points) {
Ordering::Less => {
return Err(Error::OffsetToEvlrsTooSmall(evlr.start_of_first_evlr).into());
}
Ordering::Equal => {} // pass
Ordering::Greater => {
let n = evlr.start_of_first_evlr - offset_to_end_of_points;
read.by_ref()
.take(n)
.read_to_end(&mut builder.point_padding)?;
}
}
}
read.seek(SeekFrom::Start(evlr.start_of_first_evlr))?;
builder
.evlrs
.push(raw::Vlr::read_from(&mut read, true).map(Vlr::new)?);
Expand Down

0 comments on commit db6cc85

Please sign in to comment.