r-lidar / lasR

Fast and Pipable Airborne LiDAR Data Tools
https://r-lidar.github.io/lasR/
GNU General Public License v3.0
57 stars 1 forks source link

(un)expected behaviour of pipeline with write_las + write_lax + write_vpc #68

Closed wiesehahn closed 2 months ago

wiesehahn commented 3 months ago

I have a folder with las files which are missing the correct CRS, a spatial index and are uncompressed. So I was wondering if there would be an efficient way to bring the data in a better shape.

For this I tried the following pipeline:

pipeline = set_crs(25832) + 
    write_las(ofile =paste0(tempdir(), "/*.laz")) + 
    write_lax(embedded = TRUE) + 
    write_vpc(ofile = tempfile(fileext = ".vpc")), absolute_path = TRUE, use_gpstime = TRUE) 

exec(pipeline, with = list(progress = TRUE, ncores = concurrent_files(half_cores())), on = folder)

What I wanted was that a compressed version of files is created, which include a spatial index and that these files are referenced in a VPC. Although I expected this might not work as intended due to the internal order the stages are run.

What the pipeline did is to create a spatial index (lax) as an extra file next to the las files , write compressed laz files (without embedded index) and write a vpc which references the las files.

I guess this is an edge case and everything works as expected from lasR side, just reporting it for the case this is not true.

Probably I should split this in something like the following?!

pipeline = set_crs(25832) + write_las(ofile =paste0(tempdir(), "/*.laz"))
exec(pipeline, with = list(progress = TRUE, ncores = concurrent_files(half_cores())), on = folder)

pipeline = write_lax(embedded = TRUE) + write_vpc(ofile = tempfile(fileext = ".vpc")), absolute_path = TRUE, use_gpstime = TRUE) 
exec(pipeline, with = list(progress = TRUE, ncores = concurrent_files(half_cores())), on = tempdir)
Jean-Romain commented 3 months ago

Yes everything is working as expected here. Stages are applied to the processed files.

  1. write_las() writes new LAZ files from the processed files as expected
  2. write_lax() spatially indexes the processed files and should be the first stage. If it is not the first stage? Well I should have handled the case internally. I'll check. In your case the spatial indexing is not useful here this is why you do not have any warning I guess.
  3. write_vpc() writes a VPC of the processed files. When I created write_vpc() the use case I was thinking of was only exec(write_vpc(), on = f)

So I'm pretty happy that the pipeline is working fine because you are combining all the tricky stages. But I understand it is not what you are expecting.

Your split pipelines are correct and should do what you are expecting.

Now I guess we could design something smarter like:

pipeline = set_crs(25832) + write_las(ofile =paste0(tempdir(), "/*.laz"), add_index = TRUE, create_vpc = TRUE)