Python – Converting Pointcloud Data in UTM from TXT to LAS

laslaspyliblaspythonutm

I have text file with point cloud data in UTM format, say

sample=[632535.222, 4858488.332, 150.555]

I am currently using laspy, the parsing from txt is ready, and I plan to generate a new las file using the following code:

header = laspy.LasHeader(point_format=0, version="1.3")
outfile = laspy.LasData(header)
outfile.x = utm_east
outfile.y = utm_north
outfile.z = utm_z
outfile.intensity = raw_intensity
las.write(out_path)

I am getting the error message:

ValueError: invalid literal for int() with base 10: '632535.331'

which obviously because I am trying to store a float point into 32bit signed int as data format for LAS file.

Is there any way I can get around this with while retaining the precision of the result here? Even with scaling I think it goes beyond the maximum for 32bit int.

Best Answer

You must define a scale factor and an offset. I do not know python and laspy but according to the doc it should look like

header.offset = [632000, 4858000, 0]
header.scale = [0.001, 0.001, 0.001]
Related Question