I have this little code for manipulating lidar points in a Las file. The goal is to take 1 point from file 1 and look for the closest point in the file 2. Then create a new point which using the coordinates of the points and then save it. I encountered 2 problem so far, which are explained below:
import laspy
import laspy.file
import liblas
from liblas import header
h = header.Header()
inFile2 = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\Sync\\pythonlas\\mapperclip\\2clip.las", mode = "r")
inFile3 = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\Sync\\pythonlas\\mapperclip\\3clip.las", mode = "r")
point_records = inFile2.points
point_records = inFile3.points
t=0
for points in inFile3.points:
z=0
q=0
p=0.1
while z==0:
xmin=inFile3.x[t]-p
ymin=inFile3.y[t]-p
xmax=inFile3.x[t]+p
ymax=inFile3.y[t]+p
n=0
for points in inFile2.points:
ax=inFile2.x[n]
ay=inFile2.y[n]
if ax > xmin and ax < xmax and ay < ymax and ay > ymin:
f = liblas.file.File("C:\\Users\\Geri\\Desktop\\Sync\\Sync\\pythonlas\\mapperclip\\proba.las",mode='w', header= h)
newx = inFile3.x[t]-((inFile3.x[t]-inFile2.x[n])/2)
newy = inFile3.y[t]-((inFile3.y[t]-inFile2.y[n])/2)
newz = inFile3.z[t]-((inFile3.z[t]-inFile2.z[n])/2)
pt = liblas.point.Point(newx, newy, newz)
The problem is here after this line. I want to save the newx,y,z as the X Y coordinates and z value for the new points in a new las file.
Getting the following error:
ctypes.Argumenterror: argument 1: : wrong type
f.write(pt)
f.close()
print t
print newx
print newy
print newz
print inFile2.y[n]
print inFile2.z[n]
print inFile3.z[t]
n+=1
q+=1
t+=1
else:
n+=1
if q>0:
z+=1
else:
p+=0.1
When I take out the attempt to write the file from the code then I got the following: (the script runs 415 times succesfully)
Traceback (most recent call last):
File "........
newx = inFile3.x[t]-((inFile3.x[t]-inFile2.x[n])/2)
IndexError: index 416 is out of bounds for axis 0 with size 416