-
Notifications
You must be signed in to change notification settings - Fork 1
/
header.go
325 lines (285 loc) · 12 KB
/
header.go
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// Copyright 2017 Blacksky. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lidar
import (
"fmt"
"time"
"github.com/geodatalake/lambdas/geotiff"
)
type Vlr struct {
reserved uint16
userID string
recordID uint16
lengthAfterHeader uint16
description string
data []byte
}
type Evlr struct {
reserved uint16
userID string
recordID uint16
lengthAfterHeader uint64
description string
data []byte
}
type ImageInfo struct {
width, height float64
scalex, scaley float64
offsetx, offsety float64
minx, miny, maxx, maxy, minz, maxz float64
}
type HeaderFormat interface {
GetNumberOfPoints() uint64
ScalePoints(int32, int32, int32) (float64, float64, float64)
GetPointFormat() byte
GetPointsOffset() uint64
GetPointLength() uint16
GetNumberOfVLR() uint32
GetNumberOfEVLR() uint32
GetOffsetOfEVLR() uint64
GpsTime() GpsTimeType
DateTime() (time.Time, error)
isWkt() bool
Imageinfo() *ImageInfo
DumpHeader() []string
Bounds() *geotiff.Bounds
Version() (int, int)
VersionString() string
}
type LasHeaderLegacy struct {
fileSignature string
fileSourceId uint16
globalEncoding uint16
projectIdGuid string
versionMajor byte
versionMinor byte
systemIdentifier string
generatingSoftware string
fileCreationDayOfYear uint16
fileCreationYear uint16
headerSize uint16
offsetDataPoint uint32
numVarLengthRecords uint32
pointDataRecordFormat byte
pointDataRecordLength uint16
legacyNumberPointRecords uint32
legacyNumberPointsByReturn []uint32
xScaleFactor float64
yScaleFactor float64
zScaleFactor float64
xOffset float64
yOffset float64
zOffset float64
maxX float64
minX float64
maxY float64
minY float64
maxZ float64
minZ float64
}
func (h *LasHeaderLegacy) DateTime() (time.Time, error) {
day := int(h.fileCreationDayOfYear)
year := int(h.fileCreationYear)
if tm, err := time.Parse("1-2-2006", fmt.Sprintf("1-1-%d", year)); err == nil {
return tm.Add(time.Duration(time.Hour * time.Duration(24*(day-1)))), nil
} else {
return time.Now(), err
}
}
func (h *LasHeaderLegacy) Bounds() *geotiff.Bounds {
// assume orientation upper left origin
return &geotiff.Bounds{MaxX: h.maxX, MinX: h.minX, MaxY: h.maxY, MinY: h.minY, OriginX: h.minX, OriginY: h.maxY}
}
func (h *LasHeaderLegacy) GetNumberOfVLR() uint32 {
return h.numVarLengthRecords
}
func (h *LasHeaderLegacy) GetNumberOfEVLR() uint32 {
return 0
}
func (h *LasHeaderLegacy) GetOffsetOfEVLR() uint64 {
return 0
}
func (h *LasHeaderLegacy) GetNumberOfPoints() uint64 {
return uint64(h.legacyNumberPointRecords)
}
func (h *LasHeaderLegacy) GetPointFormat() byte {
return h.pointDataRecordFormat
}
func (h *LasHeaderLegacy) ScalePoints(x int32, y int32, z int32) (float64, float64, float64) {
return float64((float64(x) * h.xScaleFactor) + h.xOffset), float64((float64(y) * h.yScaleFactor) + h.yOffset), float64((float64(z) * h.zScaleFactor) + h.zOffset)
}
func (h *LasHeaderLegacy) GetPointsOffset() uint64 {
return uint64(h.offsetDataPoint)
}
func (h *LasHeaderLegacy) GetPointLength() uint16 {
return h.pointDataRecordLength
}
func (h *LasHeaderLegacy) GpsTime() GpsTimeType {
if (int(h.globalEncoding) & geGpsMask) == 0 {
return geGpsWeekTime
} else {
return geGpsStandardOffset
}
}
func (h *LasHeaderLegacy) isWkt() bool {
return int(h.globalEncoding)&geWktMask == geWkt
}
func (h *LasHeaderLegacy) Imageinfo() *ImageInfo {
return &ImageInfo{
width: h.maxX - h.minX,
height: h.maxY - h.minY,
scalex: h.xScaleFactor,
offsetx: h.xOffset,
scaley: h.yScaleFactor,
offsety: h.yOffset,
minx: h.minX,
maxx: h.maxX,
miny: h.minY,
maxy: h.maxY,
minz: h.minZ,
maxz: h.maxZ}
}
func (h *LasHeaderLegacy) Version() (int, int) {
return int(h.versionMajor), int(h.versionMinor)
}
func (h *LasHeaderLegacy) VersionString() string {
return fmt.Sprintf("%v.%v", h.versionMajor, h.versionMinor)
}
func (h *LasHeaderLegacy) DumpHeader() []string {
retval := make([]string, 0, 28)
retval = append(retval, fmt.Sprintf("fileSignature: %s", h.fileSignature))
retval = append(retval, fmt.Sprintf("fileSourceId: %v", h.fileSourceId))
retval = append(retval, fmt.Sprintf("globalEncoding: %v", h.globalEncoding))
retval = append(retval, fmt.Sprintf("projectIdGuid: %s", h.projectIdGuid))
retval = append(retval, fmt.Sprintf("version: %v.%v", h.versionMajor, h.versionMinor))
retval = append(retval, fmt.Sprintf("systemIdentifier: %s", h.systemIdentifier))
retval = append(retval, fmt.Sprintf("generatingSoftware: %s", h.generatingSoftware))
retval = append(retval, fmt.Sprintf("fileCreationDay/Yr: %d/%d", h.fileCreationDayOfYear, h.fileCreationYear))
retval = append(retval, fmt.Sprintf("headerSize: %v", h.headerSize))
retval = append(retval, fmt.Sprintf("offsetDataPoint: %v", h.offsetDataPoint))
retval = append(retval, fmt.Sprintf("numVarLengthRecords: %v", h.numVarLengthRecords))
retval = append(retval, fmt.Sprintf("pointDataRecordFormat: %v", h.pointDataRecordFormat))
retval = append(retval, fmt.Sprintf("pointDataRecordLength: %v", h.pointDataRecordLength))
retval = append(retval, fmt.Sprintf("legacyNumberPointRecords: %v", h.legacyNumberPointRecords))
retval = append(retval, fmt.Sprintf("legacyNumberPointsByReturn: %v", h.legacyNumberPointsByReturn))
retval = append(retval, fmt.Sprintf("xScaleFactor: %f", h.xScaleFactor))
retval = append(retval, fmt.Sprintf("yScaleFactor: %f", h.yScaleFactor))
retval = append(retval, fmt.Sprintf("zScaleFactor: %f", h.zScaleFactor))
retval = append(retval, fmt.Sprintf("xOffset: %f", h.xOffset))
retval = append(retval, fmt.Sprintf("yOffset: %f", h.yOffset))
retval = append(retval, fmt.Sprintf("zOffset: %f", h.zOffset))
retval = append(retval, fmt.Sprintf("maxX: %f", h.maxX))
retval = append(retval, fmt.Sprintf("minX: %f", h.minX))
retval = append(retval, fmt.Sprintf("maxY: %f", h.maxY))
retval = append(retval, fmt.Sprintf("minY: %f", h.minY))
retval = append(retval, fmt.Sprintf("maxZ: %f", h.maxZ))
retval = append(retval, fmt.Sprintf("minZ: %f", h.minZ))
return retval
}
type LasHeader14 struct {
LasHeaderLegacy
startWaveformRecord uint64
startFirstExtendedVlr uint64
numExtendedVlr uint32
numberPointRecords uint64
numberPointsByReturn []uint64
}
func (h *LasHeader14) Bounds() *geotiff.Bounds {
// assume orientation upper left origin
return &geotiff.Bounds{MaxX: h.maxX, MinX: h.minX, MaxY: h.maxY, MinY: h.minY, OriginX: h.minX, OriginY: h.maxY}
}
func (h *LasHeader14) GetNumberOfPoints() uint64 {
if h.numberPointRecords != 0 {
return h.numberPointRecords
} else {
return uint64(h.legacyNumberPointRecords)
}
}
func (h *LasHeader14) ScalePoints(x int32, y int32, z int32) (float64, float64, float64) {
return float64((float64(x) * h.xScaleFactor) + h.xOffset), float64((float64(y) * h.yScaleFactor) + h.yOffset), float64((float64(z) * h.zScaleFactor) + h.zOffset)
}
func (h *LasHeader14) GetPointFormat() byte {
return h.pointDataRecordFormat
}
func (h *LasHeader14) GetPointsOffset() uint64 {
return uint64(h.offsetDataPoint)
}
func (h *LasHeader14) GetPointLength() uint16 {
return h.pointDataRecordLength
}
func (h *LasHeader14) GetNumberOfVLR() uint32 {
return h.numVarLengthRecords
}
func (h *LasHeader14) GetNumberOfEVLR() uint32 {
return h.numExtendedVlr
}
func (h *LasHeader14) GetOffsetOfEVLR() uint64 {
return h.startFirstExtendedVlr
}
func (h *LasHeader14) GpsTime() GpsTimeType {
if (int(h.globalEncoding) & geGpsMask) == 0 {
return geGpsWeekTime
} else {
return geGpsStandardOffset
}
}
func (h *LasHeader14) isWkt() bool {
return int(h.globalEncoding)&geWktMask == geWkt
}
func (h *LasHeader14) Version() (int, int) {
return int(h.versionMajor), int(h.versionMinor)
}
func (h *LasHeader14) VersionString() string {
return fmt.Sprintf("%v.%v", h.versionMajor, h.versionMinor)
}
func (h *LasHeader14) Imageinfo() *ImageInfo {
return &ImageInfo{
width: h.maxX - h.minX,
height: h.maxY - h.minY,
scalex: h.xScaleFactor,
offsetx: h.xOffset,
scaley: h.yScaleFactor,
offsety: h.yOffset,
minx: h.minX,
maxx: h.maxX,
miny: h.minY,
maxy: h.maxY,
minz: h.maxZ}
}
func (h *LasHeader14) DumpHeader() []string {
retval := make([]string, 0, 33)
retval = append(retval, fmt.Sprintf("fileSignature: %s", h.fileSignature))
retval = append(retval, fmt.Sprintf("fileSourceId: %v", h.fileSourceId))
retval = append(retval, fmt.Sprintf("globalEncoding: %v", h.globalEncoding))
retval = append(retval, fmt.Sprintf("projectIdGuid: %s", h.projectIdGuid))
retval = append(retval, fmt.Sprintf("version: %v.%v", h.versionMajor, h.versionMinor))
retval = append(retval, fmt.Sprintf("systemIdentifier: %s", h.systemIdentifier))
retval = append(retval, fmt.Sprintf("generatingSoftware: %s", h.generatingSoftware))
retval = append(retval, fmt.Sprintf("fileCreationDay/Yr: %d/%d", h.fileCreationDayOfYear, h.fileCreationYear))
retval = append(retval, fmt.Sprintf("headerSize: %v", h.headerSize))
retval = append(retval, fmt.Sprintf("offsetDataPoint: %v", h.offsetDataPoint))
retval = append(retval, fmt.Sprintf("numVarLengthRecords: %v", h.numVarLengthRecords))
retval = append(retval, fmt.Sprintf("pointDataRecordFormat: %v", h.pointDataRecordFormat))
retval = append(retval, fmt.Sprintf("pointDataRecordLength: %v", h.pointDataRecordLength))
retval = append(retval, fmt.Sprintf("legacyNumberPointRecords: %v", h.legacyNumberPointRecords))
retval = append(retval, fmt.Sprintf("legacyNumberPointsByReturn: %v", h.legacyNumberPointsByReturn))
retval = append(retval, fmt.Sprintf("xScaleFactor: %f", h.xScaleFactor))
retval = append(retval, fmt.Sprintf("yScaleFactor: %f", h.yScaleFactor))
retval = append(retval, fmt.Sprintf("zScaleFactor: %f", h.zScaleFactor))
retval = append(retval, fmt.Sprintf("xOffset: %f", h.xOffset))
retval = append(retval, fmt.Sprintf("yOffset: %f", h.yOffset))
retval = append(retval, fmt.Sprintf("zOffset: %f", h.zOffset))
retval = append(retval, fmt.Sprintf("maxX: %f", h.maxX))
retval = append(retval, fmt.Sprintf("minX: %f", h.minX))
retval = append(retval, fmt.Sprintf("maxY: %f", h.maxY))
retval = append(retval, fmt.Sprintf("minY: %f", h.minY))
retval = append(retval, fmt.Sprintf("maxZ: %f", h.maxZ))
retval = append(retval, fmt.Sprintf("minZ: %f", h.minZ))
retval = append(retval, fmt.Sprintf("startWaveformRecord: %v", h.startWaveformRecord))
retval = append(retval, fmt.Sprintf("startFirstExtendedVlr: %v", h.startFirstExtendedVlr))
retval = append(retval, fmt.Sprintf("numExtendedVlr: %v", h.numExtendedVlr))
retval = append(retval, fmt.Sprintf("numberPointRecords: %v", h.numberPointRecords))
retval = append(retval, fmt.Sprintf("numberPointsByReturn: %v", h.numberPointsByReturn))
return retval
}