las-laz-js 0.0.0-stage → 0.2.0
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/CHANGELOG.md +59 -0
- package/LICENSE +21 -0
- package/LICENSE-APACHE +51 -0
- package/NOTICE +14 -0
- package/README.md +197 -2
- package/package.json +49 -5
- package/src/LasReader.js +334 -0
- package/src/colour/colourize.js +161 -0
- package/src/errors.js +38 -0
- package/src/filter/dedupe.js +81 -0
- package/src/filter/filters.js +72 -0
- package/src/format/LasCrs.js +67 -0
- package/src/format/LasHeader.js +97 -0
- package/src/format/LasVlr.js +68 -0
- package/src/format/PointFormats.js +75 -0
- package/src/index.js +27 -0
- package/src/io/BlobSource.js +40 -0
- package/src/io/ByteSource.js +42 -0
- package/src/io/MemorySource.js +84 -0
- package/src/io/NodeFileSource.js +87 -0
- package/src/io/ScratchBinaryFile.js +239 -0
- package/src/laz/ArithmeticDecoder.js +136 -0
- package/src/laz/IntegerDecompressor.js +77 -0
- package/src/laz/LazVlr.js +65 -0
- package/src/laz/chunkTable.js +109 -0
- package/src/laz/decompressChunk.js +115 -0
- package/src/laz/models.js +102 -0
- package/src/laz/v2/byte.js +33 -0
- package/src/laz/v2/gpstime11.js +118 -0
- package/src/laz/v2/point10.js +139 -0
- package/src/laz/v2/rgb12.js +79 -0
- package/src/laz/v3/layered.js +145 -0
- package/src/laz/v3/point14.js +266 -0
- package/src/read/decodeRecords.js +164 -0
- package/src/read/windows.js +45 -0
- package/src/workers/lasWorker.js +16 -0
- package/src/workers/workerProtocol.js +125 -0
- package/src/write/encodeRecords.js +76 -0
- package/src/write/scaleOffset.js +24 -0
- package/src/write/writeLas.js +223 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 (2026-10-21)
|
|
4
|
+
|
|
5
|
+
Reads LAZ.
|
|
6
|
+
|
|
7
|
+
- LAZ (LASzip) point formats 0–3 and 6–8 (item versions 2 and 3; version 4 unchecked), with extra bytes, are read by `openLas` /
|
|
8
|
+
`readPoints` / `chunks` / `readPointsToScratch` and the worker exactly as LAS is: each chunk
|
|
9
|
+
is decompressed into plain LAS records, then decoded by the same code, so every option works
|
|
10
|
+
the same. Plain JavaScript, translated from laz-rs (Apache-2.0); the package licence is now
|
|
11
|
+
`MIT AND Apache-2.0` (see `NOTICE`).
|
|
12
|
+
- Checked against an independent encoder: fixtures compressed by PDAL decode to exactly PDAL's own
|
|
13
|
+
decompression, and real files to exactly their LAS twins (1 M points), or to PDAL's decompression
|
|
14
|
+
(10 M points).
|
|
15
|
+
- `reader.laz` describes the compression. Wave-packet LAZ items, LASzip item version 1 and files
|
|
16
|
+
without a chunk table are `UNSUPPORTED`; a LAZ cut short is `TRUNCATED`. `COMPRESSED_LAZ` is
|
|
17
|
+
no longer thrown.
|
|
18
|
+
- Breaking: `strideFor` (deprecated in 0.1.1) is removed.
|
|
19
|
+
- Demo: reads LAZ, and shows its compression.
|
|
20
|
+
|
|
21
|
+
## 0.1.1 (2026-10-21)
|
|
22
|
+
|
|
23
|
+
Fixes from the 0.1.0 review. No breaking changes.
|
|
24
|
+
|
|
25
|
+
- `maxPoints` keeps exactly that many of the points that pass the filters, spread over the whole
|
|
26
|
+
file. It used to keep only the start of a file, and with filters set could return nothing.
|
|
27
|
+
- Streamed chunks are coloured by one rule for the whole file, so windows no longer show seams
|
|
28
|
+
(new `createChunkColourizer`; `colourize` gains `eightBit`).
|
|
29
|
+
- Opening a LAS 1.4 file no longer reads its EVLRs to the end of the file: a big EVLR has
|
|
30
|
+
`bytes: null` until `readEvlrBytes(i)`. VLRs and EVLRs report `length`.
|
|
31
|
+
- Browser bundlers (esbuild, webpack, Vite) can bundle the package; the lazy Node import no
|
|
32
|
+
longer stops them.
|
|
33
|
+
- `readPoints` and `writeLas` peak near the size of what they return (a 69 MB read peaked at
|
|
34
|
+
233 MB, now 74 MB); Node files are read into one reused window buffer.
|
|
35
|
+
- `dedupe` is about 7 times faster.
|
|
36
|
+
- `createLasWriter` works with OPFS scratch writers and Node file handles, and with
|
|
37
|
+
`writePoints` calls made without waiting.
|
|
38
|
+
- A custom `{ size, read }` source that returns a short read is `TRUNCATED`, never fewer points.
|
|
39
|
+
- Point formats 6–10 write their coordinate system as WKT, as LAS 1.4 requires; an EPSG code
|
|
40
|
+
alone is refused for them.
|
|
41
|
+
- `strideFor` is deprecated (the reader no longer uses it) and goes in 0.2.0; `countKept` is new.
|
|
42
|
+
- Demo: bounds, dedupe, colour range, return and intensity histograms; safe on big files.
|
|
43
|
+
|
|
44
|
+
## 0.1.0 (2026-10-21)
|
|
45
|
+
|
|
46
|
+
First release: read and write ASPRS LAS.
|
|
47
|
+
|
|
48
|
+
- `openLas` reads the header, VLRs, EVLRs and coordinate system (GeoKeys / WKT) of LAS 1.0–1.4,
|
|
49
|
+
from a File / Blob, ArrayBuffer, Uint8Array, Node path or any `{ size, read }` source.
|
|
50
|
+
- `readPoints` and `chunks` decode every point format (0–10) in windows of whole records, never
|
|
51
|
+
holding the file whole; filters (classes, returns, bounds), even thinning (`maxPoints`),
|
|
52
|
+
`dedupe`, `localOrigin` + `float32`, progress and abort.
|
|
53
|
+
- `readPointsToScratch` streams columns into OPFS scratch files.
|
|
54
|
+
- `colourize` by RGB (with 8-bit files detected), intensity, elevation or classification.
|
|
55
|
+
- `writeLas` and the streaming `createLasWriter` write LAS 1.0–1.4, formats 0–10, with EPSG or
|
|
56
|
+
WKT coordinate systems.
|
|
57
|
+
- `las-laz-js/worker`: a module Worker with a documented message protocol.
|
|
58
|
+
- A Three.js demo.
|
|
59
|
+
- LAZ files open and report `compressed`; reading their points arrives in 0.2.0.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brent Buffham
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
37
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
38
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
39
|
+
|
|
40
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
41
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
42
|
+
|
|
43
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
44
|
+
|
|
45
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
46
|
+
|
|
47
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
48
|
+
|
|
49
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
50
|
+
|
|
51
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
las-laz-js
|
|
2
|
+
Copyright (c) 2026 Brent Buffham (https://kirra-design.com). MIT licence (see LICENSE).
|
|
3
|
+
|
|
4
|
+
The LAZ decoder in src/laz/ is a JavaScript translation of laz-rs
|
|
5
|
+
(https://github.com/laz-rs/laz-rs), which is itself a Rust port of LASzip
|
|
6
|
+
(https://laszip.org) by rapidlasso. Those files are licensed under the
|
|
7
|
+
Apache License, Version 2.0 (see LICENSE-APACHE), not the MIT licence:
|
|
8
|
+
|
|
9
|
+
(c) 2007-2015, martin isenburg, rapidlasso - fast tools to catch reality
|
|
10
|
+
(c) 2014, Uday Verma, Hobu, Inc.
|
|
11
|
+
(c) 2019-2023, Thomas Montaigu
|
|
12
|
+
|
|
13
|
+
Changes: translated from Rust to JavaScript by Brent Buffham, 2026. Each
|
|
14
|
+
translated file names the laz-rs source it came from in its header.
|
package/README.md
CHANGED
|
@@ -1,3 +1,198 @@
|
|
|
1
|
-
#
|
|
1
|
+
# las-laz-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A JavaScript reader and writer for ASPRS **LAS** point clouds, and a reader for **LAZ**
|
|
4
|
+
(LASzip-compressed LAS), published on npm as `las-laz-js`. Plain ES modules, no dependencies,
|
|
5
|
+
runs in the browser and in Node — and built for files far larger than memory.
|
|
6
|
+
|
|
7
|
+
**Status: early (0.x).** It works and is tested, but the API may still change before 1.0.
|
|
8
|
+
|
|
9
|
+
- Working: `openLas` reads the header, VLRs / EVLRs and coordinate system of LAS 1.0–1.4;
|
|
10
|
+
`readPoints` and `chunks` decode every point format (0–10) a window at a time, with filters
|
|
11
|
+
and thinning; `colourize` colours points; `writeLas` writes LAS 1.0–1.4.
|
|
12
|
+
- LAZ: point formats 0–3 and 6–8, with extra bytes, read exactly like LAS — the same calls, the
|
|
13
|
+
same options, decoded chunk by chunk in plain JavaScript (no WebAssembly).
|
|
14
|
+
- Big files: a 1.1 GB, 34-million-point LAS reads in under a second in Node, and a 10-million-point
|
|
15
|
+
LAZ decodes at about 1.8 million points a second; neither is held in memory whole (see LAZ below
|
|
16
|
+
for the one exception).
|
|
17
|
+
- Also: a ready-made module Worker (`las-laz-js/worker`) and a
|
|
18
|
+
[Three.js demo](https://brentbuffham.github.io/las-laz-js/).
|
|
19
|
+
- Not yet: writing LAZ (0.3.0).
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install las-laz-js
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Node 22 or newer, or any current browser. No dependencies.
|
|
28
|
+
|
|
29
|
+
## Demo
|
|
30
|
+
|
|
31
|
+
Try it in the browser: **https://brentbuffham.github.io/las-laz-js/**
|
|
32
|
+
|
|
33
|
+
Drop a LAS or LAZ file onto the page. It is read locally (never uploaded), in the library's
|
|
34
|
+
Worker, and streamed into a Three.js viewer. The side panel shows the header, VLRs, coordinate
|
|
35
|
+
system and LAZ compression; reads with class, return, bounds, thinning and dedupe filters;
|
|
36
|
+
colours by RGB, intensity, elevation or class; lists point statistics; and saves the points back
|
|
37
|
+
out as LAS. To run it locally: `npm run demo`, then open http://localhost:8080/.
|
|
38
|
+
|
|
39
|
+
## Reading
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { openLas } from "las-laz-js";
|
|
43
|
+
|
|
44
|
+
var las = await openLas(file); // File / Blob, ArrayBuffer, Uint8Array, a Node path, or { size, read }
|
|
45
|
+
las.header; // { versionMajor, versionMinor, pointFormat, pointCount, bounds, scale, offset,
|
|
46
|
+
// software, systemId, creationDay, creationYear, pointsByReturn, compressed, ... }
|
|
47
|
+
las.crs; // { kind: "geokeys" | "wkt" | null, epsg, wkt?, keys? } — parsed, never reprojected
|
|
48
|
+
las.vlrs; // [{ userId, recordId, description, start, length, bytes }]
|
|
49
|
+
las.evlrs; // the same; an EVLR over 64 KiB (waveform data) has bytes: null until
|
|
50
|
+
// await las.readEvlrBytes(i) — opening never reads it
|
|
51
|
+
las.compressed; las.laz; // true for LAZ; its compressor, chunk size and items (else null)
|
|
52
|
+
|
|
53
|
+
var pts = await las.readPoints({
|
|
54
|
+
fields: ["x", "y", "z", "classification", "red", "green", "blue"],
|
|
55
|
+
classes: [2], // keep only these classification codes
|
|
56
|
+
returns: [1], // keep only these return numbers
|
|
57
|
+
bounds: { minX, maxX, minY, maxY, minZ, maxZ },
|
|
58
|
+
maxPoints: 5000000, // even thinning; 0 keeps every point
|
|
59
|
+
dedupe: 0.01, // drop points within 1 cm (XY; dedupeZ: true for 3D)
|
|
60
|
+
localOrigin: { x: 478000, y: 6772000 }, float32: true, // small Float32 coordinates for the GPU
|
|
61
|
+
onProgress: function (fraction, label) {},
|
|
62
|
+
signal: abortController.signal
|
|
63
|
+
});
|
|
64
|
+
pts.count; pts.x; pts.y; pts.z; // one typed array per field
|
|
65
|
+
pts.bounds; pts.stats; // world bounds, per-class counts
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Fields: `x y z intensity returnNumber numberOfReturns scanDirection edgeOfFlightLine
|
|
69
|
+
classification classificationFlags scannerChannel scanAngle userData pointSourceId gpsTime
|
|
70
|
+
red green blue nir`. Fields a point format does not hold are left out. `scanAngle` is in
|
|
71
|
+
degrees for every format.
|
|
72
|
+
|
|
73
|
+
Filters run on the raw record before it is decoded, so a filtered-out point costs a byte read.
|
|
74
|
+
`maxPoints` keeps exactly that many of the points that pass the filters, spread evenly over
|
|
75
|
+
the whole file; with filters set it first counts the passing points, which reads the file twice.
|
|
76
|
+
|
|
77
|
+
## LAZ
|
|
78
|
+
|
|
79
|
+
A LAZ file is opened and read with the same calls as LAS. Each LASzip chunk (50,000 points in
|
|
80
|
+
most files) is decompressed into the plain LAS records it holds, then decoded exactly as a LAS
|
|
81
|
+
window is — so every option above works the same, and reading a LAZ gives the same columns as
|
|
82
|
+
reading the LAS it was compressed from.
|
|
83
|
+
|
|
84
|
+
- Read: point formats 0–3 (LASzip point-wise, item version 2) and 6–8 (layered, item version 3),
|
|
85
|
+
with extra bytes. Item version 4 follows laz-rs but has not been checked against a real file
|
|
86
|
+
(it differs from 3 only with several scanner channels).
|
|
87
|
+
- Not read: wave-packet items (formats 4, 5, 9, 10 in LAZ), item version 1 (LASzip before 2011),
|
|
88
|
+
and files without a chunk table (an unfinished write). Each is refused with `UNSUPPORTED`,
|
|
89
|
+
naming what it found — never garbage points.
|
|
90
|
+
- A LAZ file cut short is `TRUNCATED`.
|
|
91
|
+
|
|
92
|
+
## Files bigger than memory
|
|
93
|
+
|
|
94
|
+
`openLas` reads only the header and the VLRs. Points are read in windows (64 MiB of records by
|
|
95
|
+
default, `openLas(file, { windowSize })`; for LAZ, whole chunks adding up to about that much
|
|
96
|
+
decompressed), so memory holds one window plus what you keep. One exception: a LAZ written
|
|
97
|
+
point-wise without chunks (LASzip before 2.0, rare) is one chunk, so its window is the whole
|
|
98
|
+
decompressed file.
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
for await (var chunk of las.chunks({ fields: ["x", "y", "z"] })) {
|
|
102
|
+
draw(chunk); // one window's points
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
In the browser, `readPointsToScratch` streams the selected columns into OPFS scratch files (one
|
|
107
|
+
per field) instead of memory; run it in a Worker, which OPFS sync access needs.
|
|
108
|
+
|
|
109
|
+
## Colour
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
import { colourize } from "las-laz-js";
|
|
113
|
+
var rgb = colourize(pts, { by: "elevation" }); // "rgb" | "intensity" | "elevation" | "classification"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Returns a `Uint8Array`, three bytes per point. LAS colour is 16-bit and is scaled to 8 bits —
|
|
117
|
+
except in files that store 8-bit values in the 16-bit fields (a common writer bug), which are
|
|
118
|
+
detected and used as they are instead of turning almost black. Elevation uses a blue → cyan →
|
|
119
|
+
green → yellow → red ramp; intensity a greyscale over the 2nd–98th percentile; classification
|
|
120
|
+
the usual LiDAR-viewer colours (ASPRS defines the codes, not colours). For streamed chunks,
|
|
121
|
+
`createChunkColourizer` keeps one rule for the whole file, so windows match.
|
|
122
|
+
|
|
123
|
+
## Writing
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
import { writeLas, createLasWriter } from "las-laz-js";
|
|
127
|
+
|
|
128
|
+
var bytes = await writeLas(pts, { version: "1.2", pointFormat: 3, crs: { epsg: 28350 } });
|
|
129
|
+
var v14 = await writeLas(pts, { version: "1.4", pointFormat: 7, crs: { wkt: las.crs.wkt } });
|
|
130
|
+
|
|
131
|
+
var w = await createLasWriter(sink, { version: "1.2", pointFormat: 3, scale, offset });
|
|
132
|
+
// sink: an OPFS writer from openScratchSyncWriter, a Node FileHandle, or any { write(bytes, position) }
|
|
133
|
+
await w.writePoints(batch1); await w.writePoints(batch2);
|
|
134
|
+
await w.close(); // patches the header totals
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
A version and point format that do not go together (format 6 in LAS 1.2) are refused, never
|
|
138
|
+
silently changed. Scale and offset are chosen from the bounds when not given. `crs.epsg`
|
|
139
|
+
writes a GeoKey record; `crs.wkt` a WKT record. Point formats 6–10 must carry WKT (LAS 1.4), so
|
|
140
|
+
an EPSG code alone is refused for them — the library has no projection database to turn a code
|
|
141
|
+
into WKT. Writing LAZ arrives in 0.3.0.
|
|
142
|
+
|
|
143
|
+
## In a Worker
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
var worker = new Worker(new URL("las-laz-js/worker", import.meta.url), { type: "module" });
|
|
147
|
+
worker.postMessage({ id: 1, type: "open", payload: { blob: file } });
|
|
148
|
+
worker.postMessage({ id: 2, type: "chunks", payload: { fields: ["x", "y", "z"], colour: { by: "rgb" } } });
|
|
149
|
+
// replies: { id, type: "progress" | "chunk" | "result" | "error", ... }; buffers are transferred
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The protocol is documented in `src/workers/workerProtocol.js` and can be driven directly with
|
|
153
|
+
`createWorkerHandler(post)`.
|
|
154
|
+
|
|
155
|
+
## Errors
|
|
156
|
+
|
|
157
|
+
Every failure is a `LasError` with a stable `code` (`ERROR_CODES`) and, for byte-level problems,
|
|
158
|
+
the file `offset`: `NOT_LAS`, `UNSUPPORTED_VERSION`, `UNSUPPORTED`, `TRUNCATED`, `BAD_HEADER`,
|
|
159
|
+
`BAD_VLR`, `INVALID_ARGUMENT`, `ABORTED`, `TOO_MANY_POINTS`. A file shorter than its header
|
|
160
|
+
promises is `TRUNCATED`, never garbage points. (`COMPRESSED_LAZ` is kept for 0.1 callers but is no
|
|
161
|
+
longer thrown: LAZ is read.)
|
|
162
|
+
|
|
163
|
+
## Scope
|
|
164
|
+
|
|
165
|
+
Reprojection is out of scope (the coordinate system is reported, not changed). Waveform
|
|
166
|
+
formats 4, 5, 9 and 10 have their point fields read from LAS; the waveform data itself is not.
|
|
167
|
+
COPC, EPT and E57 are not read.
|
|
168
|
+
|
|
169
|
+
## Provenance
|
|
170
|
+
|
|
171
|
+
The LAS reader, writer and big-file handling come from [Kirra](https://kirra-design.com),
|
|
172
|
+
Brent Buffham's blast-design app, rewritten as a standalone library. The LAZ decoder in
|
|
173
|
+
`src/laz/` is a JavaScript translation of [laz-rs](https://github.com/laz-rs/laz-rs) by Thomas
|
|
174
|
+
Montaigu, itself a Rust port of [LASzip](https://laszip.org) by Martin Isenburg (rapidlasso).
|
|
175
|
+
It is checked against an independent encoder: the test fixtures were compressed by
|
|
176
|
+
[PDAL](https://pdal.io), and every record must equal PDAL's own decompression.
|
|
177
|
+
Formats are written to the ASPRS LAS 1.4 R15 specification; see `docs/LAS_FORMAT_NOTES.md`.
|
|
178
|
+
|
|
179
|
+
## Development
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
npm test # node --test, every test
|
|
183
|
+
npm run test:coverage # with the coverage gate
|
|
184
|
+
npm run demo # the demo on http://localhost:8080/
|
|
185
|
+
npm run check:private # before every push: no private sample details in the repo
|
|
186
|
+
node _dev/makeLazFixtures.mjs # remake test/fixtures/laz with PDAL (needs PDAL 2.x)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Private sample files go in the gitignored `samples/` folder, or are listed by path in
|
|
190
|
+
`samples/paths.txt`; the sample tests compare each file with its own header, and each LAZ with a
|
|
191
|
+
LAS twin (same count and bounds) field by field.
|
|
192
|
+
|
|
193
|
+
## Licence
|
|
194
|
+
|
|
195
|
+
`MIT AND Apache-2.0`. The library is MIT © Brent Buffham (`LICENSE`). The LAZ decoder in
|
|
196
|
+
`src/laz/`, translated from laz-rs / LASzip, is under the Apache License 2.0 (`LICENSE-APACHE`,
|
|
197
|
+
`NOTICE`). Both are permissive: use, change and ship it in open or closed software, keeping the
|
|
198
|
+
notices.
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "las-laz-js",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Zero-dependency JavaScript reader and writer for ASPRS LAS point clouds, and reader for LAZ (LASzip), for the browser and Node, built for files larger than memory.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.js",
|
|
8
|
+
"./worker": "./src/workers/lasWorker.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"LICENSE-APACHE",
|
|
15
|
+
"NOTICE",
|
|
16
|
+
"CHANGELOG.md"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node --test \"test/**/*.test.js\"",
|
|
24
|
+
"test:coverage": "node --test --experimental-test-coverage --test-coverage-include=\"src/**\" --test-coverage-lines=97 --test-coverage-branches=88 --test-coverage-functions=97 \"test/**/*.test.js\"",
|
|
25
|
+
"demo": "node _dev/serve.mjs",
|
|
26
|
+
"check:private": "node _dev/checkPrivate.mjs"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"las",
|
|
30
|
+
"laz",
|
|
31
|
+
"lidar",
|
|
32
|
+
"point-cloud",
|
|
33
|
+
"pointcloud",
|
|
34
|
+
"asprs",
|
|
35
|
+
"gis",
|
|
36
|
+
"survey",
|
|
37
|
+
"opfs",
|
|
38
|
+
"threejs"
|
|
39
|
+
],
|
|
40
|
+
"author": "Brent Buffham (https://kirra-design.com)",
|
|
41
|
+
"license": "MIT AND Apache-2.0",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/brentbuffham/las-laz-js.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/brentbuffham/las-laz-js/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/brentbuffham/las-laz-js#readme"
|
|
50
|
+
}
|