我尝试使此代码打开LAS文件进行更改,然后将结果保存到新的LAS文件中。 las文件包含具有坐标(X和Y)和值(如高程的Z)的点。 我有这个几乎工作的代码。唯一的事情是将结果点保存到新的las文件中。
import laspy
import laspy.file
import numpy as np
header = laspy.header.Header()
inFile2 = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\pythonlas\\mapperclip\\2clip.las", mode = "r")
inFile3 = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\pythonlas\\mapperclip\\3clip.las", mode = "r")
point_records = inFile2.points
point_records = inFile3.points
t=0
listx1=np.array([], dtype=float)
listy1=np.array([], dtype=float)
listz1=np.array([], dtype=float)
while t < 415:
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:
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)]
listx1=np.append(listx1, (newx))
listy1=np.append(listy1, (newy))
listz1=np.append(listz1, (newz))
print listx1
print n
n+=1
q+=1
t+=1
else:
n+=1
if q>0:
z+=1
else:
p+=0.1
outfile = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\pythonlas\\mapperclip\\output2.las", mode="w", header=header)
outfile.X = [listx1]
outfile.Y = [listy1]
outfile.Z = [listz1]
outfile.close()
当我尝试存储X值时,我遇到了这个问题:
Traceback (most recent call last):
File "C:\Users\Geri\Desktop\Sync\pythonlas\envisecond.py", line 48, in <module>
outfile.X = [listx1]
File "C:\Python27\lib\site-packages\laspy\file.py", line 277, in set_x
self._writer.set_x(x)
File "C:\Python27\lib\site-packages\laspy\base.py", line 1257, in set_x
self.set_dimension("X", X)
File "C:\Python27\lib\site-packages\laspy\base.py", line 1107, in set_dimension
return(self._set_dimension(spec, new_dim))
File "C:\Python27\lib\site-packages\laspy\base.py", line 1113, in _set_dimension
self.data_provider._pmap["point"][spec.name] = value
ValueError: setting an array element with a sequence.
答案 0 :(得分:1)
在这一行
outfile.X = [listx1]
您尝试分配包含一个元素的outfile.X
列表 - np.array
listx1
。并期望np.array
。尝试使用以下代码
outfile.X = listx1
outfile.Y = listy1
outfile.Z = listz1