我知道这听起来像一个简单的问题,一个简单的解决方案,但我就是不能把我的头围绕在它上面。
laspy
的文档有点稀疏,但到目前为止我管理得很好。我认为,现在的问题是对“矮胖”不太熟悉。
我想要根据GPS时间来排序一个numpy数组.
我的立场如下:
我正在使用laspy附带的sample.las进行测试。
import laspy
import numpy as np
#open the file
lasFile = laspy.file.File("C:/Anaconda3/Lib/site-packages/laspytest/data/simple.las", mode = "rw")
#put points in numpy array
lasPoints = lasFile.points
我要做的是按照gps_time列对数组进行排序。
print(lasPoints.dtype)
给我
[('point', [('X', '<i4'), ('Y', '<i4'), ('Z', '<i4'), ('intensity', '<u2'), ('flag_byte', 'u1'), ('raw_classification', 'u1'), ('scan_angle_rank', 'i1'), ('user_data', 'u1'), ('pt_src_id', '<u2'), ('gps_time', '<f8'), ('red', '<u2'), ('green', '<u2'), ('blue', '<u2')])]
和
print(lasPoints)
给我
[ ((63701224, 84902831, 43166, 143, 73, 1, -9, 132, 7326, 245380.78254963, 68, 77, 88),)
((63689633, 84908770, 44639, 18, 81, 1, -11, 128, 7326, 245381.45279924, 54, 66, 68),)
((63678474, 84910666, 42671, 118, 9, 1, -10, 122, 7326, 245382.13595007, 112, 97, 114),)
...,
((63750167, 85337575, 41752, 43, 9, 1, 11, 124, 7334, 249772.21013494, 100, 96, 120),)
((63743327, 85323084, 42408, 31, 9, 1, 11, 125, 7334, 249772.70733372, 176, 138, 164),)
((63734285, 85324032, 42392, 116, 73, 1, 9, 124, 7334, 249773.20172407, 138, 107, 136),)]
要访问我可以运行的gps_time
lasPoints[0][0][9] ## first gps_time in array
lasPoints[1][0][9] ## second gps_time in array
将"gps_time“替换为9会产生相同的结果。
现在,当我试图对我的数据进行排序时,它似乎并没有对任何内容进行排序:
np.sort(lasPoints["point"]["gps_time"])
print(lasPoints)
数组被打印出来,没有排序,
lasPoints=np.sort(lasPoints["point"]["gps_time"])
print(lasPoints)
结果将gps_time按如下方式排序:
[ 245370.41706456 245370.74331403 245371.06452222 ..., 249782.07498673
249782.64531958 249783.16215837]
我哪里出问题了?
发布于 2017-10-20 07:37:49
就我所理解的文档而言,np.sort似乎不支持内部排序。然而,np.ndarray.sort确实如此。所以
np.sort(lasPoints["point"]["gps_time"])
print(lasPoints)
永远不会被整理好。
但对于您的问题:您可以将GPS时间列表从列表中分割出来,并使用argsort获取排序列表的索引。这些可以用来分类你的套索。例如:
sorted_ind = np.argsort(list_of_gpstimes)
laspoints = laspoints[sorted_ind]
发布于 2017-10-20 08:24:02
为了完全结束这个问题,并在dudakl的回答的基础上,使用np.ndarray进行排序,这对我来说是有效的:
np.ndarray.sort(lasPoints["point"],kind='mergesort',order='gps_time')
这里的关键是指定lasPoint“点”,然后通过gps_time进行排序。
这里只对gps_time颜色进行排序,而没有其他颜色。
np.ndarray.sort(lasPoints["point"]["gps_time])
https://stackoverflow.com/questions/46844233
复制相似问题