我有两个文件,一个是(.shp),另一个是点云(.las)。
使用laspy和shapefile模块,我设法找到了.las文件的哪些点属于shapefile的特定多边形。我现在要做的是添加一个索引号,以便在两个数据集之间进行识别。因此,例如,在多边形231内的所有点都应该得到231。
问题是,到目前为止,在编写.las文件时,我无法将任何内容添加到点列表中。我想要做的代码是:
outFile1 = laspy.file.File("laswrite2.las", mode = "w",header = inFile.header)
outFile1.points = truepoints
outFile1.points.append(indexfromshp)
outFile1.close()我现在遇到的错误是: AttributeError:'numpy.ndarray‘对象没有属性'append’。我已经尝试过多个东西,包括np.append,但是对于如何向las文件添加任何内容,我真的很困惑。
任何帮助都是非常感谢的!
发布于 2018-06-20 12:37:02
有几种方法可以做到这一点。
Las文件有分类字段,可以将索引存储在此字段中。
las_file = laspy.file.File("las.las", mode="rw")
las_file.classification = indexfromshp但是,如果Las文件的版本为<= 1.2,则分类字段只能在0,35范围内存储值,但可以使用“user_data”字段,该字段可以在0,255范围内保存值。
或者,如果您需要存储高于255的值/需要一个单独的字段,则可以定义一个新的维度(参见laspy关于如何添加额外维度的文档)。您的代码应该非常接近这样的内容。
outFile1 = laspy.file.File("laswrite2.las", mode = "w",header = inFile.header)
# copy fields
for dimension in inFile.point_format:
dat = inFile.reader.get_dimension(dimension.name)
outFile1.writer.set_dimension(dimension.name, dat)
outFile1.define_new_dimension(
name="index_from_shape",
data_type=7, # uint64_t
description = "Index of corresponding polygon from shape file"
)
outFile1.index_from_shape = indexfromshp
outFile1.close()https://stackoverflow.com/questions/50815580
复制相似问题