【发布时间】:2017-03-17 22:39:33
【问题描述】:
我在 python 中工作并尝试从多个 LAZ 文件中获取 x、y、z 坐标,并将它们放入一个数组中,以用于另一次分析。我正在尝试自动执行此任务,因为我有大约 2000 个文件可以变成一个甚至 10 个数组。该示例涉及两个文件,但我无法使循环正常工作。我认为我没有正确命名我的变量。下面是我一直在尝试编写的示例代码(请注意,我对编程非常陌生,如果这是一个糟糕的代码,请道歉)。
创建 las 文件列表,然后将它们转换为数组——尝试更好的自动化
import numpy as np
from laspy.file import File
import glob as glob
# create list of vegetation files to be opened
VegList = sorted(glob.glob('/Users/sophiathompson/Desktop/copys/Clips/*.las'))
for f in VegList:
print(f)
Veg = File(filename = f, mode = "r") # Open the file
points = Veg.get_points() # Grab all of the points from the file.
print points #this is a check that the number of rows changes at the end
print ("array shape:")
print points.shape
VegListCoords = np.vstack((Veg.x, Veg.y, Veg.z)).transpose()
print VegListCoords
此块读取两个文件,但用文件列表中第二个文件的结果填充VegListCoords。我需要它来保存两者的记录。如果这是一种可怕的方法,我对一种新方法非常开放。
【问题讨论】:
标签: python arrays loops csv numpy