@thi.ng/pixel-io-geotiff 0.1.49 → 0.1.51
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 +1 -1
- package/package.json +8 -6
- package/read.js +38 -38
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/pixel-io-geotiff",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.51",
|
|
4
4
|
"description": "GeoTIFF reader support for @thi.ng/pixel",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,13 +35,13 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/pixel": "^5.0.
|
|
38
|
+
"@thi.ng/api": "^8.9.12",
|
|
39
|
+
"@thi.ng/pixel": "^5.0.4",
|
|
38
40
|
"geotiff": "2.0.7"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
43
|
"@microsoft/api-extractor": "^7.38.3",
|
|
42
|
-
"
|
|
44
|
+
"esbuild": "^0.19.8",
|
|
43
45
|
"rimraf": "^5.0.5",
|
|
44
46
|
"tools": "^0.0.1",
|
|
45
47
|
"typedoc": "^0.25.4",
|
|
@@ -85,5 +87,5 @@
|
|
|
85
87
|
"status": "alpha",
|
|
86
88
|
"year": 2023
|
|
87
89
|
},
|
|
88
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
89
91
|
}
|
package/read.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
import { typedArrayType } from "@thi.ng/api";
|
|
2
2
|
import { FLOAT_GRAY_RANGE, floatBuffer } from "@thi.ng/pixel";
|
|
3
3
|
import { Pool, fromArrayBuffer } from "geotiff";
|
|
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
|
-
|
|
4
|
+
const readGeoTiff = async (src, opts = {}) => {
|
|
5
|
+
const tiff = await fromArrayBuffer(src.buffer);
|
|
6
|
+
const tiffImg = await tiff.getImage();
|
|
7
|
+
const width = tiffImg.getWidth();
|
|
8
|
+
const height = tiffImg.getHeight();
|
|
9
|
+
const pool = opts.pool instanceof Pool ? opts.pool : opts.pool ? new Pool() : void 0;
|
|
10
|
+
const data = (await tiffImg.readRasters({ pool, samples: [opts.channel || 0] }))[0];
|
|
11
|
+
const type = typedArrayType(data);
|
|
12
|
+
const [min, max] = opts.range ? opts.range : data.reduce(
|
|
13
|
+
(acc, x) => {
|
|
14
|
+
acc[0] = Math.min(acc[0], x);
|
|
15
|
+
acc[1] = Math.max(acc[1], x);
|
|
16
|
+
return acc;
|
|
17
|
+
},
|
|
18
|
+
[Infinity, -Infinity]
|
|
19
|
+
);
|
|
20
|
+
const fmt = FLOAT_GRAY_RANGE(min, max);
|
|
21
|
+
let img;
|
|
22
|
+
switch (type) {
|
|
23
|
+
case "i8":
|
|
24
|
+
case "u8":
|
|
25
|
+
case "i16":
|
|
26
|
+
case "u16":
|
|
27
|
+
case "i32":
|
|
28
|
+
case "u32":
|
|
29
|
+
img = floatBuffer(width, height, fmt, new Float32Array(data));
|
|
30
|
+
break;
|
|
31
|
+
case "f32":
|
|
32
|
+
img = floatBuffer(width, height, fmt, data);
|
|
33
|
+
break;
|
|
34
|
+
case "f64":
|
|
35
|
+
img = floatBuffer(width, height, fmt, new Float32Array(data));
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
return { img, tiff: tiffImg };
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
readGeoTiff
|
|
42
42
|
};
|