Convert Numpy array in las file with laspy

674 views Asked by At

I'm trying to save a NumPy array in a las file. The problem is that the file that is created only contains x y z coordinates, and no info related to intensity, classification, and return number are stored. Here it is my code. I think it's a problem related to the header, but I don't know how to correctly set it.

Can anyone help me?

array=[np.random(10000,6)]

header = laspy.header.Header()
x=array[:,0]
y=array[:,1]
z=array[:,2]
intensity=array[:,3]
return_num=array[:,4]
classification=array[:,5]

xmin = np.floor(np.min(x))
ymin = np.floor(np.min(y))
zmin = np.floor(np.min(z))

outfile = laspy.file.File(r"...array.las", mode="w", header=header)
outfile.header.offset = [xmin,ymin,zmin]
outfile.header.scale = [0.001,0.001,0.001]
outfile.x = x
outfile.y = y
outfile.z = z
outfile.intensity = intensity
outfile.return_num = return_num
outfile.classification = classification
outfile.close()
1

There are 1 answers

1
max31ru12 On

Try something like that: In short: - To read a file do: las = laspy.read('somefile.laz') - To create a new LAS data do: las = laspy.create(point_format=2, file_version='1.2') - To write a file previously read or created: las.write('somepath.las') See the documentation for more information about the changes https://laspy.readthedocs.io/en/latest/