I am trying to add an extra dimension/attribute to my existing LAS/LAZ file and then create/write a new LAS/LAZ file using laspy (version 2.5.3). Later, I want to use that extra_dim for my further work or visualization. I use the below code, particularly add_extra_dim() for adding the new dimention to the out_file. I see that both data point formats are same, but still getting an error related to IncompatibleDataFormat: Cannot set points with a different point format, convert first.
Can anyone help with this or a way out to create the file?
Code I am using below:
in_las = laspy.read('o6580_145.laz')
rgb_values = np.vstack((in_las.red, in_las.green, in_las.blue)).T
normalized_rgb = rgb_values
G = normalized_rgb[:, 1]
R = normalized_rgb[:, 0]
B = normalized_rgb[:, 2]
veg_index = (2 * G - R - B) / (2 * G + R + B)
veg_index_float32 = veg_index.astype(np.float32)
out_las = laspy.create(file_version=in_las.header.version, point_format=3)
out_las.header = in_las.header
out_las.user_data = veg_index_float32
for dimension in in_las.point_format:
setattr(out_las, dimension.name, getattr(in_las, dimension.name))
out_las.add_extra_dim(laspy.ExtraBytesParams(name="veg_index", type="float32", description="Vegetation Index"))
out_las.write('out_las.las')
The error IncompatibleDataFormat: pops up in the second-last code line add_extra_dim().
Can anyone help with suggesting any solution? Or anyone would like to give it a try, the LAZ file is here for download: https://fileport.io/Bx1EREpvntLP
Thank you