r-lidar / rlas

R package to read and write las and laz files used to store LiDAR data
https://cran.r-project.org/package=rlas
GNU General Public License v3.0
34 stars 14 forks source link

write.las writes a deeply corrupted file #25

Open jstrunk001 opened 5 years ago

jstrunk001 commented 5 years ago

Hello, I have a specific set of laz files that result in strange behavior when read / write with lidR

library(lidR)
las1 = readLAS("SubArea_012_011.8_6.las")
las1
f = tempfile(fileext = ".las")
writeLAS(las1, f)
las2 = readLAS(f)
las2

SubArea_012_011.8_6.las.zip

Jean-Romain commented 5 years ago

The error is reproducible without lidR. Moving the issue to rlas


data1 = read.las("~/Téléchargements/SubArea_012_011.8_6.las")
header1 = read.lasheader("~/Téléchargements/SubArea_012_011.8_6.las")

f = tempfile(fileext = ".las")

write.las(f, header1, data1)

data2 = read.las(f)
#> ERROR: 'end-of-file' after 6359 of 6365 points
#> Warning: there are 19 points flagged 'withheld'.
#> Warning: there are 3658 points flagged 'synthetic'.

header2 = read.lasheader(f)
Jean-Romain commented 5 years ago

Well, I found the issue. But in the meantime I don't know how to fix it and I'm not even sure if I should fix it. Basically the header states to add an offset in the binary file but this offset is not respected. I'm not going through details. The following fixes your issues waiting for a better internal fix.

library(lidR)

las = readLAS("SubArea_012_011.8_6.las")
las@header@PHB$`Header Size` = 235

f = tempfile(fileext = ".las")
writeLAS(las, f)

I'm wondering if @floriandeboissieu have a better understanding of the header size management in LASlib

jstrunk001 commented 5 years ago

Ok, thank you JR!

floriandeboissieu commented 5 years ago

Sorry for the late answer, I don't have much time this end of year. I'll dig into it as soon as I can.