tmontaigu / pylas

⚠️ pylas was merged into laspy 2.0 https://github.com/laspy/laspy⚠️
BSD 3-Clause "New" or "Revised" License
39 stars 13 forks source link

Piping LAS with extra bytes through laszip.exe to compress it produces bad files #11

Closed tmontaigu closed 4 years ago

tmontaigu commented 4 years ago

Using a script like this:

import sys
import io

import pylas

las = pylas.read(sys.argv[1])

las.write("tmp.laz")

with io.BytesIO() as out:
    las.write(out, do_compress=True)
    out.seek(0)
    pylas.read(out)

if sys.argv[1] is a file with extra bytes, the tmp.laz will be invalid (lasinfo will output errors like

[...]
ERROR: 'end-of-file' after 454 of 1065 points for '.\tmp.laz'
corrupt chunk table
[...]

And pylas will fail to read the file with an error like

pylas.errors.PylasError: The file does not contain enough bytes to store the expected number of points
expected 64965 bytes, read 27703 bytes (37262 bytes missing == 610.8524590163935 points) and it cannot be corrected
27703 (bytes) / 61 (point_size) = 454.1475409836066 (points)

however if the file at sys.argv[1] does not have extra bytes everything is fine.

tmontaigu commented 4 years ago

Fixed by 61b6541c959de8aa03135af21b08564e43086411 it had nothing to do with extra bytes, but with writing LAZ 1.4 files using laszip.exe Basically the Las1.4.write_to was rewriting the header that laszip wrote.

I wounldn't be surprised if there were more problems with writing LAZ1.4 files using laszip.exe