8

I am trying to process a large .las file received, which appears to have been scaled in non-standard ways for some reason (likely data transfer portability). The scales between x, y, z are different in and in the range of 10^-5 instead of 0.01 or so. The odd scales in non-standard values prevents me from processing or writing the LAS files with writeLAS or other commands, with an error of:

Error: Invalid header: X scale factors should be factor ten of 0.1 or 0.5 or 0.25 not 1.06228168611949e-05

Is there a good way to actually rescale the point cloud with the lidR package?

I know that the scale factors can be accessed through the header information, as per the code and output from sample LAS file below.

I also seek additional discussion on what it means to rescale the point cloud, and what should be used for physical interpretation and writing to DEMs rather than storage.

Sample reading in and displaying header info in R:

    LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
    las <- readLAS(LASfile)
    las@header
    # las@header@PHB

Output includes:

Scale factor X Y Z:       0.01 0.01 0.01 

Currently using lidR version 2.02 and rlas version 1.3.1.

11
  • 2
    for rescaling you could use lastools >> las2las -i *.las -rescale 0.01 0.01 0.01 rapidlasso.com/lastools
    – zwnk
    Commented Aug 28, 2019 at 15:29
  • Are you sure this is a valid .las file and not corrupted somehow? Can you read it in anything else? That scale looks.... bad...
    – Spacedman
    Commented Aug 28, 2019 at 16:48
  • Agreed that the scale seems super bad. It manages to read and even plot in various programs (lidR, LAStools), so the las file itself appears to have valid data that shows up generally as expected. But not ruling out that the scaling is somehow incorrect or corrupt.
    – Rob
    Commented Aug 28, 2019 at 17:07
  • 1
    @zwnk the free version of lastools will mess up your data. I highly recommend steering clear of it with larger point clouds especially. The licensed version may be a different story. See this post:gis.stackexchange.com/questions/118479/…
    – Kartograaf
    Commented Aug 28, 2019 at 17:18
  • 2
    @Cory G las2las is 100% free and open source. No limitation with big data.
    – JRR
    Commented Aug 28, 2019 at 17:22

1 Answer 1

6

lidR should not throw an error for that, at read time. It is invalid but not corrupted so it is readable. However writeLAS do throw an error. You have two solutions. The first one should be preferred in my opinion.

Fix your original files with las2las from lastools. las2las should be preferred for every tasks that imply las file processing. Use:

 las2las -i *.las -rescale 0.01 0.01 0.01

The other option, if you have already read your file in R. Fix manually the header.

las <- readLAS("file.las")
las@header@PHB[["X scale factor"]] <- 0.01
las@header@PHB[["Y scale factor"]] <- 0.01
las@header@PHB[["Z scale factor"]] <- 0.01
writeLAS(las, "file2.las")

Edit: lidR 2.1.3 will have two new functions lasrescale() and lasreoffset(). See on github.

4
  • Thanks @JRR! In this case since the header likely just erroneous and the scaling is fine, relabelling it in R as you have works well. I also found the lastool function in the uavRst package as a wrapper for lastools if someone wanted to strictly stay within R (rdocumentation.org/packages/uavRst/versions/0.5-2/topics/…), but lastools command line works well too. Thanks again
    – Rob
    Commented Aug 28, 2019 at 18:58
  • Small additional comment, it does not cause an error at read time or during plotting with the plot function. But for writeLAS or any processing (e.g. lasfilterduplicates, lasfilterground, etc.) it does seem to throw an error.
    – Rob
    Commented Aug 28, 2019 at 18:59
  • 1
    uavRst is no longer a package on CRAN. For writeLAS it is expected. For other function it should warn only. This will be improved later.
    – JRR
    Commented Aug 28, 2019 at 19:20
  • @JRR But sir the manually chosen scale factor should be able to convert the coordinate to integer no? Commented Apr 10 at 11:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.