Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将索引附加到laspy文件(.las)_Python_File_Shapefile_Laspy - Fatal编程技术网

Python 将索引附加到laspy文件(.las)

Python 将索引附加到laspy文件(.las),python,file,shapefile,laspy,Python,File,Shapefile,Laspy,我有两个文件,一个是esri形状文件(.shp),另一个是点云(.las) 使用laspy和shapefile模块,我成功地找到了.las文件的哪些点位于shapefile的特定多边形内。我现在想做的是添加一个索引号,以实现两个数据集之间的标识。因此,例如,多边形231内的所有点都应获得编号231 问题是,到目前为止,在编写.las文件时,我还无法在点列表中添加任何内容。我尝试使用的代码片段如下: outFile1 = laspy.file.File("laswrite2.las", mode

我有两个文件,一个是esri形状文件(.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文件添加任何内容


非常感谢您的帮助

有几种方法可以做到这一点

Las文件有分类字段,您可以在该字段中存储索引

las_file = laspy.file.File("las.las", mode="rw")
las_file.classification = indexfromshp

但是,如果Las文件有版本,我发现在复制字段之前调用define_new_dimension是可行的。
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()