@loaders.gl/las 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +16141 -15332
- package/dist/dist.min.js +29 -0
- package/dist/index.cjs +118 -326
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/las-loader.d.ts +1 -1
- package/dist/las-loader.d.ts.map +1 -1
- package/dist/las-loader.js +23 -18
- package/dist/lib/get-las-schema.d.ts +1 -1
- package/dist/lib/get-las-schema.d.ts.map +1 -1
- package/dist/lib/get-las-schema.js +37 -26
- package/dist/lib/las-types.js +0 -1
- package/dist/lib/laslaz-decoder.d.ts +1 -1
- package/dist/lib/laslaz-decoder.d.ts.map +1 -1
- package/dist/lib/laslaz-decoder.js +357 -285
- package/dist/lib/libs/laz-perf.js +19004 -2
- package/dist/lib/parse-las.d.ts +2 -2
- package/dist/lib/parse-las.d.ts.map +1 -1
- package/dist/lib/parse-las.js +172 -160
- package/dist/workers/las-worker.js +0 -1
- package/package.json +10 -7
- package/dist/index.js.map +0 -1
- package/dist/las-loader.js.map +0 -1
- package/dist/lib/get-las-schema.js.map +0 -1
- package/dist/lib/las-types.js.map +0 -1
- package/dist/lib/laslaz-decoder.js.map +0 -1
- package/dist/lib/libs/laz-perf.js.map +0 -1
- package/dist/lib/parse-las.js.map +0 -1
- package/dist/workers/las-worker.js.map +0 -1
|
@@ -1,316 +1,388 @@
|
|
|
1
1
|
import getModule from "./libs/laz-perf.js";
|
|
2
2
|
let Module = null;
|
|
3
3
|
const POINT_FORMAT_READERS = {
|
|
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
|
-
|
|
4
|
+
0: (dv) => {
|
|
5
|
+
return {
|
|
6
|
+
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
7
|
+
intensity: dv.getUint16(12, true),
|
|
8
|
+
classification: dv.getUint8(15)
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
1: (dv) => {
|
|
12
|
+
return {
|
|
13
|
+
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
14
|
+
intensity: dv.getUint16(12, true),
|
|
15
|
+
classification: dv.getUint8(15)
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
2: (dv) => {
|
|
19
|
+
return {
|
|
20
|
+
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
21
|
+
intensity: dv.getUint16(12, true),
|
|
22
|
+
classification: dv.getUint8(15),
|
|
23
|
+
color: [dv.getUint16(20, true), dv.getUint16(22, true), dv.getUint16(24, true)]
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
3: (dv) => {
|
|
27
|
+
return {
|
|
28
|
+
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
29
|
+
intensity: dv.getUint16(12, true),
|
|
30
|
+
classification: dv.getUint8(15),
|
|
31
|
+
color: [dv.getUint16(28, true), dv.getUint16(30, true), dv.getUint16(32, true)]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Reads incoming binary data depends on the Type parameter
|
|
37
|
+
* @param buf
|
|
38
|
+
* @param Type
|
|
39
|
+
* @param offset
|
|
40
|
+
* @param count
|
|
41
|
+
* @returns number | number[] from incoming binary data
|
|
42
|
+
*/
|
|
43
|
+
function readAs(buf, Type = {}, offset, count) {
|
|
44
|
+
count = count === undefined || count === 0 ? 1 : count;
|
|
45
|
+
const sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count);
|
|
46
|
+
const r = new Type(sub);
|
|
47
|
+
if (count === 1) {
|
|
48
|
+
return r[0];
|
|
49
|
+
}
|
|
50
|
+
const ret = [];
|
|
51
|
+
for (let i = 0; i < count; i++) {
|
|
52
|
+
ret.push(r[i]);
|
|
53
|
+
}
|
|
54
|
+
return ret;
|
|
50
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Parsing of header's attributes
|
|
58
|
+
* @param arraybuffer
|
|
59
|
+
* @returns header as LASHeader
|
|
60
|
+
*/
|
|
51
61
|
function parseLASHeader(arraybuffer) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
let start = 32 * 3 + 35;
|
|
63
|
+
const o = {
|
|
64
|
+
pointsOffset: readAs(arraybuffer, Uint32Array, 32 * 3),
|
|
65
|
+
pointsFormatId: readAs(arraybuffer, Uint8Array, 32 * 3 + 8),
|
|
66
|
+
pointsStructSize: readAs(arraybuffer, Uint16Array, 32 * 3 + 8 + 1),
|
|
67
|
+
pointsCount: readAs(arraybuffer, Uint32Array, 32 * 3 + 11),
|
|
68
|
+
scale: readAs(arraybuffer, Float64Array, start, 3)
|
|
69
|
+
};
|
|
70
|
+
start += 24; // 8*3
|
|
71
|
+
o.offset = readAs(arraybuffer, Float64Array, start, 3);
|
|
72
|
+
start += 24;
|
|
73
|
+
const bounds = readAs(arraybuffer, Float64Array, start, 6);
|
|
74
|
+
start += 48; // 8*6;
|
|
75
|
+
o.maxs = [bounds[0], bounds[2], bounds[4]];
|
|
76
|
+
o.mins = [bounds[1], bounds[3], bounds[5]];
|
|
77
|
+
return o;
|
|
68
78
|
}
|
|
79
|
+
// LAS Loader
|
|
80
|
+
// Loads uncompressed files
|
|
81
|
+
//
|
|
69
82
|
class LASLoader {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.arraybuffer = arraybuffer;
|
|
88
|
-
}
|
|
89
|
-
open() {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
getHeader() {
|
|
93
|
-
this.header = parseLASHeader(this.arraybuffer);
|
|
94
|
-
return this.header;
|
|
95
|
-
}
|
|
96
|
-
readData(count, skip) {
|
|
97
|
-
const {
|
|
98
|
-
header,
|
|
99
|
-
arraybuffer
|
|
100
|
-
} = this;
|
|
101
|
-
if (!header) {
|
|
102
|
-
throw new Error('Cannot start reading data till a header request is issued');
|
|
103
|
-
}
|
|
104
|
-
let {
|
|
105
|
-
readOffset
|
|
106
|
-
} = this;
|
|
107
|
-
let start;
|
|
108
|
-
if (skip <= 1) {
|
|
109
|
-
count = Math.min(count, header.pointsCount - readOffset);
|
|
110
|
-
start = header.pointsOffset + readOffset * header.pointsStructSize;
|
|
111
|
-
const end = start + count * header.pointsStructSize;
|
|
112
|
-
readOffset += count;
|
|
113
|
-
this.readOffset = readOffset;
|
|
114
|
-
return {
|
|
115
|
-
buffer: arraybuffer.slice(start, end),
|
|
116
|
-
count,
|
|
117
|
-
hasMoreData: readOffset < header.pointsCount
|
|
118
|
-
};
|
|
83
|
+
constructor(arraybuffer) {
|
|
84
|
+
this.readOffset = 0;
|
|
85
|
+
this.header = {
|
|
86
|
+
pointsOffset: 0,
|
|
87
|
+
pointsFormatId: 0,
|
|
88
|
+
pointsStructSize: 0,
|
|
89
|
+
pointsCount: 0,
|
|
90
|
+
scale: [0, 0, 0],
|
|
91
|
+
offset: [0, 0, 0],
|
|
92
|
+
maxs: [0],
|
|
93
|
+
mins: [0],
|
|
94
|
+
totalToRead: 0,
|
|
95
|
+
totalRead: 0,
|
|
96
|
+
versionAsString: '',
|
|
97
|
+
isCompressed: true
|
|
98
|
+
};
|
|
99
|
+
this.arraybuffer = arraybuffer;
|
|
119
100
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
start = header.pointsOffset + readOffset * header.pointsStructSize;
|
|
127
|
-
const src = new Uint8Array(arraybuffer, start, header.pointsStructSize);
|
|
128
|
-
buf.set(src, pointsRead * header.pointsStructSize);
|
|
129
|
-
pointsRead++;
|
|
130
|
-
}
|
|
131
|
-
readOffset++;
|
|
101
|
+
/**
|
|
102
|
+
* @returns boolean
|
|
103
|
+
*/
|
|
104
|
+
open() {
|
|
105
|
+
// Nothing needs to be done to open this
|
|
106
|
+
return true;
|
|
132
107
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
close() {
|
|
141
|
-
this.arraybuffer = null;
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
class LAZLoader {
|
|
146
|
-
constructor(arraybuffer) {
|
|
147
|
-
this.arraybuffer = void 0;
|
|
148
|
-
this.instance = null;
|
|
149
|
-
this.header = null;
|
|
150
|
-
this.arraybuffer = arraybuffer;
|
|
151
|
-
if (!Module) {
|
|
152
|
-
Module = getModule();
|
|
108
|
+
/**
|
|
109
|
+
* Parsing of incoming binary
|
|
110
|
+
* @returns LASHeader
|
|
111
|
+
*/
|
|
112
|
+
getHeader() {
|
|
113
|
+
this.header = parseLASHeader(this.arraybuffer);
|
|
114
|
+
return this.header;
|
|
153
115
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Reading data
|
|
118
|
+
* @param count
|
|
119
|
+
* @param skip
|
|
120
|
+
* @returns new ArrayBuffer, count, hasMoreData
|
|
121
|
+
*/
|
|
122
|
+
readData(count, skip) {
|
|
123
|
+
const { header, arraybuffer } = this;
|
|
124
|
+
if (!header) {
|
|
125
|
+
throw new Error('Cannot start reading data till a header request is issued');
|
|
126
|
+
}
|
|
127
|
+
let { readOffset } = this;
|
|
128
|
+
let start;
|
|
129
|
+
if (skip <= 1) {
|
|
130
|
+
count = Math.min(count, header.pointsCount - readOffset);
|
|
131
|
+
start = header.pointsOffset + readOffset * header.pointsStructSize;
|
|
132
|
+
const end = start + count * header.pointsStructSize;
|
|
133
|
+
readOffset += count;
|
|
134
|
+
this.readOffset = readOffset;
|
|
135
|
+
return {
|
|
136
|
+
buffer: arraybuffer.slice(start, end),
|
|
137
|
+
count,
|
|
138
|
+
hasMoreData: readOffset < header.pointsCount
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const pointsToRead = Math.min(count * skip, header.pointsCount - readOffset);
|
|
142
|
+
const bufferSize = Math.ceil(pointsToRead / skip);
|
|
143
|
+
let pointsRead = 0;
|
|
144
|
+
const buf = new Uint8Array(bufferSize * header.pointsStructSize);
|
|
145
|
+
for (let i = 0; i < pointsToRead; i++) {
|
|
146
|
+
if (i % skip === 0) {
|
|
147
|
+
start = header.pointsOffset + readOffset * header.pointsStructSize;
|
|
148
|
+
const src = new Uint8Array(arraybuffer, start, header.pointsStructSize);
|
|
149
|
+
buf.set(src, pointsRead * header.pointsStructSize);
|
|
150
|
+
pointsRead++;
|
|
151
|
+
}
|
|
152
|
+
readOffset++;
|
|
153
|
+
}
|
|
154
|
+
this.readOffset = readOffset;
|
|
155
|
+
return {
|
|
156
|
+
buffer: buf.buffer,
|
|
157
|
+
count: pointsRead,
|
|
158
|
+
hasMoreData: readOffset < header.pointsCount
|
|
159
|
+
};
|
|
171
160
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Method which brings data to null to close the file
|
|
163
|
+
* @returns
|
|
164
|
+
*/
|
|
165
|
+
close() {
|
|
166
|
+
// @ts-ignore Possibly null
|
|
167
|
+
this.arraybuffer = null;
|
|
168
|
+
return true;
|
|
176
169
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* LAZ Loader
|
|
173
|
+
* Uses NaCL module to load LAZ files
|
|
174
|
+
*/
|
|
175
|
+
class LAZLoader {
|
|
176
|
+
constructor(arraybuffer) {
|
|
177
|
+
this.instance = null; // LASZip instance
|
|
178
|
+
this.header = null;
|
|
179
|
+
this.arraybuffer = arraybuffer;
|
|
180
|
+
if (!Module) {
|
|
181
|
+
// Avoid executing laz-perf on import
|
|
182
|
+
Module = getModule();
|
|
183
|
+
}
|
|
184
184
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Opens the file
|
|
187
|
+
* @returns boolean
|
|
188
|
+
*/
|
|
189
|
+
open() {
|
|
190
|
+
try {
|
|
191
|
+
const { arraybuffer } = this;
|
|
192
|
+
this.instance = new Module.LASZip();
|
|
193
|
+
const abInt = new Uint8Array(arraybuffer);
|
|
194
|
+
const buf = Module._malloc(arraybuffer.byteLength);
|
|
195
|
+
this.instance.arraybuffer = arraybuffer;
|
|
196
|
+
this.instance.buf = buf;
|
|
197
|
+
Module.HEAPU8.set(abInt, buf);
|
|
198
|
+
this.instance.open(buf, arraybuffer.byteLength);
|
|
199
|
+
this.instance.readOffset = 0;
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
throw new Error(`Failed to open file: ${error.message}`);
|
|
204
|
+
}
|
|
189
205
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
206
|
+
getHeader() {
|
|
207
|
+
if (!this.instance) {
|
|
208
|
+
throw new Error('You need to open the file before trying to read header');
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const header = parseLASHeader(this.instance.arraybuffer);
|
|
212
|
+
header.pointsFormatId &= 0x3f;
|
|
213
|
+
this.header = header;
|
|
214
|
+
return header;
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throw new Error(`Failed to get header: ${error.message}`);
|
|
218
|
+
}
|
|
196
219
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
instance
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
220
|
+
/**
|
|
221
|
+
* @param count
|
|
222
|
+
* @param offset
|
|
223
|
+
* @param skip
|
|
224
|
+
* @returns Data
|
|
225
|
+
*/
|
|
226
|
+
readData(count, offset, skip) {
|
|
227
|
+
if (!this.instance) {
|
|
228
|
+
throw new Error('You need to open the file before trying to read stuff');
|
|
229
|
+
}
|
|
230
|
+
const { header, instance } = this;
|
|
231
|
+
if (!header) {
|
|
232
|
+
throw new Error('You need to query header before reading, I maintain state that way, sorry :(');
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const pointsToRead = Math.min(count * skip, header.pointsCount - instance.readOffset);
|
|
236
|
+
const bufferSize = Math.ceil(pointsToRead / skip);
|
|
237
|
+
let pointsRead = 0;
|
|
238
|
+
const thisBuf = new Uint8Array(bufferSize * header.pointsStructSize);
|
|
239
|
+
const bufRead = Module._malloc(header.pointsStructSize);
|
|
240
|
+
for (let i = 0; i < pointsToRead; i++) {
|
|
241
|
+
instance.getPoint(bufRead);
|
|
242
|
+
if (i % skip === 0) {
|
|
243
|
+
const a = new Uint8Array(Module.HEAPU8.buffer, bufRead, header.pointsStructSize);
|
|
244
|
+
thisBuf.set(a, pointsRead * header.pointsStructSize);
|
|
245
|
+
pointsRead++;
|
|
246
|
+
}
|
|
247
|
+
instance.readOffset++;
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
buffer: thisBuf.buffer,
|
|
251
|
+
count: pointsRead,
|
|
252
|
+
hasMoreData: instance.readOffset < header.pointsCount
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
throw new Error(`Failed to read data: ${error.message}`);
|
|
209
257
|
}
|
|
210
|
-
instance.readOffset++;
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
buffer: thisBuf.buffer,
|
|
214
|
-
count: pointsRead,
|
|
215
|
-
hasMoreData: instance.readOffset < header.pointsCount
|
|
216
|
-
};
|
|
217
|
-
} catch (error) {
|
|
218
|
-
throw new Error(`Failed to read data: ${error.message}`);
|
|
219
258
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Deletes the instance
|
|
261
|
+
* @returns boolean
|
|
262
|
+
*/
|
|
263
|
+
close() {
|
|
264
|
+
try {
|
|
265
|
+
if (this.instance !== null) {
|
|
266
|
+
this.instance.delete();
|
|
267
|
+
this.instance = null;
|
|
268
|
+
}
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
throw new Error(`Failed to close file: ${error.message}`);
|
|
273
|
+
}
|
|
230
274
|
}
|
|
231
|
-
}
|
|
232
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Helper class: Decodes LAS records into points
|
|
278
|
+
*/
|
|
233
279
|
class LASDecoder {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
280
|
+
constructor(buffer, len, header) {
|
|
281
|
+
this.arrayb = buffer;
|
|
282
|
+
this.decoder = POINT_FORMAT_READERS[header.pointsFormatId];
|
|
283
|
+
this.pointsCount = len;
|
|
284
|
+
this.pointSize = header.pointsStructSize;
|
|
285
|
+
this.scale = header.scale;
|
|
286
|
+
this.offset = header.offset;
|
|
287
|
+
this.mins = header.mins;
|
|
288
|
+
this.maxs = header.maxs;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Decodes data depends on this point size
|
|
292
|
+
* @param index
|
|
293
|
+
* @returns New object
|
|
294
|
+
*/
|
|
295
|
+
getPoint(index) {
|
|
296
|
+
if (index < 0 || index >= this.pointsCount) {
|
|
297
|
+
throw new Error('Point index out of range');
|
|
298
|
+
}
|
|
299
|
+
const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
|
|
300
|
+
return this.decoder(dv);
|
|
255
301
|
}
|
|
256
|
-
const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
|
|
257
|
-
return this.decoder(dv);
|
|
258
|
-
}
|
|
259
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* A single consistent interface for loading LAS/LAZ files
|
|
305
|
+
*/
|
|
260
306
|
export class LASFile {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
307
|
+
constructor(arraybuffer) {
|
|
308
|
+
this.formatId = 0;
|
|
309
|
+
this.isCompressed = true;
|
|
310
|
+
this.isOpen = false;
|
|
311
|
+
this.version = 0;
|
|
312
|
+
this.versionAsString = '';
|
|
313
|
+
this.arraybuffer = arraybuffer;
|
|
314
|
+
if (this.determineVersion() > 13) {
|
|
315
|
+
throw new Error('Only file versions <= 1.3 are supported at this time');
|
|
316
|
+
}
|
|
317
|
+
this.determineFormat();
|
|
318
|
+
if (POINT_FORMAT_READERS[this.formatId] === undefined) {
|
|
319
|
+
throw new Error('The point format ID is not supported');
|
|
320
|
+
}
|
|
321
|
+
this.loader = this.isCompressed
|
|
322
|
+
? new LAZLoader(this.arraybuffer)
|
|
323
|
+
: new LASLoader(this.arraybuffer);
|
|
272
324
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
325
|
+
/**
|
|
326
|
+
* Determines format in parameters of LASHeaer
|
|
327
|
+
*/
|
|
328
|
+
determineFormat() {
|
|
329
|
+
const formatId = readAs(this.arraybuffer, Uint8Array, 32 * 3 + 8);
|
|
330
|
+
const bit7 = (formatId & 0x80) >> 7;
|
|
331
|
+
const bit6 = (formatId & 0x40) >> 6;
|
|
332
|
+
if (bit7 === 1 && bit6 === 1) {
|
|
333
|
+
throw new Error('Old style compression not supported');
|
|
334
|
+
}
|
|
335
|
+
this.formatId = formatId & 0x3f;
|
|
336
|
+
this.isCompressed = bit7 === 1 || bit6 === 1;
|
|
276
337
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
338
|
+
/**
|
|
339
|
+
* Determines version
|
|
340
|
+
* @returns version
|
|
341
|
+
*/
|
|
342
|
+
determineVersion() {
|
|
343
|
+
const ver = new Int8Array(this.arraybuffer, 24, 2);
|
|
344
|
+
this.version = ver[0] * 10 + ver[1];
|
|
345
|
+
this.versionAsString = `${ver[0]}.${ver[1]}`;
|
|
346
|
+
return this.version;
|
|
285
347
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
348
|
+
/**
|
|
349
|
+
* Reads if the file is open
|
|
350
|
+
* @returns boolean
|
|
351
|
+
*/
|
|
352
|
+
open() {
|
|
353
|
+
if (this.loader.open()) {
|
|
354
|
+
this.isOpen = true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Gets the header
|
|
359
|
+
* @returns Header
|
|
360
|
+
*/
|
|
361
|
+
getHeader() {
|
|
362
|
+
return this.loader.getHeader();
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* @param count
|
|
366
|
+
* @param start
|
|
367
|
+
* @param skip
|
|
368
|
+
* @returns Data
|
|
369
|
+
*/
|
|
370
|
+
readData(count, start, skip) {
|
|
371
|
+
return this.loader.readData(count, start, skip);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Closes the file
|
|
375
|
+
*/
|
|
376
|
+
close() {
|
|
377
|
+
if (this.loader.close()) {
|
|
378
|
+
this.isOpen = false;
|
|
379
|
+
}
|
|
298
380
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
readData(count, start, skip) {
|
|
304
|
-
return this.loader.readData(count, start, skip);
|
|
305
|
-
}
|
|
306
|
-
close() {
|
|
307
|
-
if (this.loader.close()) {
|
|
308
|
-
this.isOpen = false;
|
|
381
|
+
/**
|
|
382
|
+
*/
|
|
383
|
+
getUnpacker() {
|
|
384
|
+
return LASDecoder;
|
|
309
385
|
}
|
|
310
|
-
}
|
|
311
|
-
getUnpacker() {
|
|
312
|
-
return LASDecoder;
|
|
313
|
-
}
|
|
314
386
|
}
|
|
315
387
|
export const LASModuleWasLoaded = false;
|
|
316
|
-
|
|
388
|
+
/* eslint no-use-before-define: 2 */
|