-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLas.py
111 lines (83 loc) · 3.56 KB
/
Las.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
cBLUE (comprehensive Bathymetric Lidar Uncertainty Estimator)
Copyright (C) 2019
Oregon State University (OSU)
Center for Coastal and Ocean Mapping/Joint Hydrographic Center, University of New Hampshire (CCOM/JHC, UNH)
NOAA Remote Sensing Division (NOAA RSD)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Contact:
Christopher Parrish, PhD
School of Construction and Civil Engineering
101 Kearney Hall
Oregon State University
Corvallis, OR 97331
(541) 737-5688
"""
import pandas as pd
import logging
import numpy as np
import numexpr as ne
import laspy
"""
This class provides the functionality to load las files into cBLUE. One Las object
is created for each loaded las file.
"""
class Las:
def __init__(self, las):
self.las = las
self.las_short_name = las.split('\\')[-1]
self.las_base_name = self.las_short_name.replace('.las', '')
self.inFile = laspy.file.File(self.las, mode="r")
self.num_file_points = self.inFile.__len__()
self.points_to_process = self.inFile.points['point']
self.unq_flight_lines = self.get_flight_line_ids()
'''index list that would sort gps_time (to be used to
later when exporting las data and calculated tpu to a las
file
'''
self.time_sort_indices = None
def get_flight_line_ids(self):
"""generates a list of unique flight line ids
This method returns a list of unique flight line ids.
:return: ndarray
"""
# pandas' unique faster than numpy's ?
return pd.unique(self.points_to_process['pt_src_id'])
def get_flight_line_txyz(self):
"""retrieves the x, y, z, and timestamp data from the las data points
The x, y, and z values in the las file are stored as integers. The
scale and offset values in the las file header are used to convert
the integer values to decimal values with centimeter precision.
:param ? fl:
:return: np.array, np.array, np.array, np.array
"""
scale_x = np.asarray(self.inFile.header.scale[0])
scale_y = np.asarray(self.inFile.header.scale[1])
scale_z = np.asarray(self.inFile.header.scale[2])
offset_x = np.asarray(self.inFile.header.offset[0])
offset_y = np.asarray(self.inFile.header.offset[1])
offset_z = np.asarray(self.inFile.header.offset[2])
t = self.points_to_process['gps_time']
X = self.points_to_process['X']
Y = self.points_to_process['Y']
Z = self.points_to_process['Z']
x = ne.evaluate("X * scale_x + offset_x")
y = ne.evaluate("Y * scale_y + offset_y")
z = ne.evaluate("Z * scale_z + offset_z")
self.time_sort_indices = t.argsort()
xyzt = np.vstack([x, y, z, t]).T
flight_lines = self.points_to_process['pt_src_id']
return xyzt, self.time_sort_indices, flight_lines
if __name__ == '__main__':
pass