Skip to content

Commit 3327be5

Browse files
authored
Merge pull request #2 from vojtatom/dev
Releasing 1.0.0
2 parents 26afad8 + fdcea9a commit 3327be5

File tree

6 files changed

+65
-9
lines changed

6 files changed

+65
-9
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ TypeScript package for loading LAS/LAZ, primary developed for for WebGL applicat
1313
npm install lazts
1414
```
1515

16-
| Branch | |
17-
| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18-
| Release | [![LAZts CI Release](https://github.com/vojtatom/laz.ts/actions/workflows/ci.yaml/badge.svg?branch=release)](https://github.com/vojtatom/laz.ts/actions/workflows/ci.yaml) |
19-
| Dev | [![LAZts CI Dev](https://github.com/vojtatom/laz.ts/actions/workflows/ci.yaml/badge.svg?branch=dev)](https://github.com/vojtatom/laz.ts/actions/workflows/ci.yaml) |
20-
2116
## Usage
2217

2318
```ts
@@ -53,3 +48,11 @@ interface LazData {
5348
};
5449
}
5550
```
51+
52+
When working with funky coordinates (e.g. the coordinates are too big and there is no offset), you can use the `adjustOffset` option:
53+
54+
```ts
55+
const dataWithNonZeroOffset = await parse(buffer, {
56+
adjustOffset: true,
57+
});
58+
```

lazts/src/adjust.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { LASData } from './types';
2+
3+
export function adjust(data: LASData) {
4+
//find centroid
5+
const positions = data.attributes.position.value as Int32Array;
6+
if (!positions) return;
7+
8+
const center = [0, 0, 0];
9+
for (let i = 0; i < positions.length; i++) center[i % 3] += positions[i];
10+
11+
//update centroid so that it is only the non-decimal part shifted
12+
const scale = data.header.scale;
13+
center[0] /= positions.length / 3;
14+
center[0] = Math.round(Math.round(center[0] * scale[0]) / scale[0]);
15+
center[1] /= positions.length / 3;
16+
center[1] = Math.round(Math.round(center[1] * scale[1]) / scale[1]);
17+
center[2] /= positions.length / 3;
18+
center[2] = Math.round(Math.round(center[2] * scale[2]) / scale[2]);
19+
20+
console.log(center);
21+
22+
//adjust
23+
for (let i = 0; i < positions.length; i++) positions[i] -= center[i % 3];
24+
25+
//update header
26+
data.header.offset[0] += Math.round(center[0] * scale[0]);
27+
data.header.offset[1] += Math.round(center[1] * scale[1]);
28+
data.header.offset[2] += Math.round(center[2] * scale[2]);
29+
}

lazts/src/parse.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import { LASData, LASHeader } from './types';
22
import { logStatistics } from './log';
33
import { parseLASChunked } from './parseChunk';
4+
import { adjust } from './adjust';
45

5-
export async function parse(arrayBuffer: ArrayBuffer): Promise<LASData> {
6+
interface ParseOptions {
7+
adjustOffset?: boolean;
8+
skip?: number;
9+
}
10+
11+
export async function parse(arrayBuffer: ArrayBuffer, options?: ParseOptions): Promise<LASData> {
612
const lasData: LASData = {
713
header: {} as LASHeader,
814
attributes: {},
915
};
1016

11-
await parseLASChunked(arrayBuffer, lasData, 1);
17+
const { adjustOffset = false, skip = 1 } = options || {};
18+
19+
await parseLASChunked(arrayBuffer, lasData, skip);
20+
21+
if (adjustOffset) adjust(lasData);
1222
logStatistics(lasData, arrayBuffer.byteLength);
1323
return lasData;
1424
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "lazts",
33
"private": false,
4-
"version": "0.1.0",
4+
"version": "1.0.0",
55
"type": "module",
66
"repository": {
77
"type": "git",

test/test.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@ test('Basic test LAZ', async () => {
88
console.log(data);
99
});
1010

11-
test('Basic test LAA', async () => {
11+
test('Basic test LAS', async () => {
1212
const buffer = openFileAsArray('testdata/test.las');
1313
const data = await parse(buffer);
1414
console.log(data);
1515
});
16+
17+
test('Basic test no offset LAZ', async () => {
18+
const buffer = openFileAsArray('testdata/testNoOffset.laz');
19+
const data = await parse(buffer);
20+
console.log(data);
21+
data.header.offset.forEach((v) => expect(v).toBeCloseTo(0));
22+
23+
const dataAdjusted = await parse(buffer, {
24+
adjustOffset: true,
25+
});
26+
27+
console.log(dataAdjusted);
28+
dataAdjusted.header.offset.forEach((v) => expect(v).not.toBeCloseTo(0));
29+
});

testdata/testNoOffset.laz

158 KB
Binary file not shown.

0 commit comments

Comments
 (0)