My lidR version is 2.0.2

I am trying to add an extrabyte about treeID that I get from raster (lasmergespatial with vector is super slow). I have a problem with saving that extrabyte to LAS file.

I have following code:


path <- "path/to/two/las_files.las"

ctg <- catalog(path)

tif <- raster("Segmenty_Obszar13_TIF.tif")
las = readLAS(ctg$filename[[1]], filter = "-keep_class 4 5")
tif_crop = raster::crop(tif, raster::extent(las)*1.1)
las_tree = lasmergespatial(las, tif_crop, "treeID")
lasaddextrabytes(las_tree, name="treeID", desc="ID of a tree")

Now las_tree has summary:

class        : LAS (LASF v1.4)
point format : 7
memory       : 474.4 Mb 
extent       :7497590, 7498410, 5788790, 5789610 (xmin, xmax, ymin, ymax)
coord. ref.  : NA 
area         : 670422.1 units² (convex hull)
points       : 4011573 points
density      : 5.98 points/units²
names        : X Y Z gpstime Intensity ReturnNumber NumberOfReturns ScanDirectionFlag EdgeOfFlightline Classification ScannerChannel Synthetic_flag Keypoint_flag Withheld_flag Overlap_flag ScanAngle UserData PointSourceID R G B Amplitude Pulse width treeID 
File signature:           LASF 
File source ID:           0 
Project ID - GUID:        00000000-0000-0000-0000-000000000000 
Version:                  1.4
System identifier:        LAStools (c) by rapidlasso GmbH 
Generating software:      lasheight (181108) commercial 
File creation d/y:        12/2019
header size:              375 
Offset to point data:     815 
Num. var. length record:  1 
Point data format:        7 
Point data record length: 40 
Num. of point records:    4011573 
Num. of points by return: 
Scale factor X Y Z:       0.01 0.01 0.01 
Offset X Y Z:             0 0 0 
min X Y Z:                7497590 5788790 -1.58 
max X Y Z:                7498410 5789610 38.92 
Variable length records: 
   Variable length record 1 of 1 
       Description:  RIEGL Extra Bytes 
       Extra Bytes Description:
          Amplitude: Echo signal amplitude [dB]
          Pulse width: Full width at half maximum [ns]

Seems like header is not updated after lasaddextrabytes. Am I doing something wrong?

I try also to write las_tree to new file:

writeLAS(las_tree, "new.las")
las_new = readLAS("new.las")

But las_new does not contain "treeID" attribute at all and the header is similar to the header of las_tree. How can I export LAS with extra bytes?

1 Answer 1


Seems like I found the solution. I forgot that as from version 2.0 of lidR, point clouds are not passed by reference.

Here's the solution:

las_tree = lasaddextrabytes(las_tree, name="treeID", desc="ID of a tree")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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