1

I want to create a LAS object from scratch with number of returns up to 15 (according to LAS v1.4) like:

data <- data.frame(X = runif(100, 0, 100), 
                   Y = runif(100, 0, 100), 
                   Z = runif(100, 0, 20), 
                   NumberOfReturns = rep(15L, 100)) 
LAS(data)

However, this results in

Error: Invalid data: NumberOfReturns is not an unsigned integer on 3 bits

It appears that lidr LAS objects are initialized as v1.2 by default.

Is there a way to create LAS objects with v1.4?

1 Answer 1

0

Yes you have to create and edit the header manually. I acknowledged that lidR has not a lot of tools to create custom files format. This one could have been inferred automatically.

library(lidR)

data <- data.frame(X = runif(100, 0, 100), 
                   Y = runif(100, 0, 100), 
                   Z = runif(100, 0, 20), 
                   NumberOfReturns = rep(15L, 100))

header = LASheader(data)
header@PHB[["Global Encoding"]][["WKT"]] <- TRUE
header@PHB[["Version Minor"]] <- 4L
header@PHB[["Point Data Format ID"]] <- 6L
header@PHB[["Header Size"]] <- 375L
header@PHB[["Offset to point data"]] <- 375L
LAS(data, header)

Notice the use of format 6. Only above 6 the number of returns is a 4 bits field.

Also you can get rid of

header@PHB[["Header Size"]] <- 375L
header@PHB[["Offset to point data"]] <- 375L

This is not actually useful and will be infered automatically at write time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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