-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.mjs
147 lines (116 loc) · 3.82 KB
/
test.mjs
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
import { writeFileSync } from "node:fs";
import test from "flug";
import { fromFile, fromUrl } from "geotiff";
import writeImage from "write-image";
import { default as createTile } from "./dist/esm/geotiff-tile.mjs";
import srvd from "srvd";
const writeResult = (result, filepath) => {
let { data } = result;
if (data.length === 1) data = [data[0], data[0], data[0]];
const { data: buf } = writeImage({ data, height: result.height, format: "PNG", width: result.width });
writeFileSync(`./test-output/${filepath}.png`, buf);
};
test("simple", async ({ eq }) => {
const url = "./data/wildfires.tiff";
const geotiff = await fromFile(url);
const image = await geotiff.getImage();
const image_height = image.getHeight(); // 784
const image_width = image.getWidth(); // 1052
const { height, width, tile, extra } = await createTile({
geotiff,
geotiff_srs: "simple",
bbox: [0, 0, 512, image_height + 200],
bbox_srs: "simple",
debug_level: 10,
method: "near",
tile_height: 512,
tile_layout: "[band][row][column]",
tile_srs: "simple",
tile_width: 512,
timed: true
});
console.log({ height, width, tile, extra });
const { readResult } = extra;
writeResult(readResult, "simple-raw");
// console.log("set of raw values:", new Set(rawdata.flat(1).map(arr => Array.from(arr)).flat(1)));
writeResult({ data: tile }, "simple-tile");
});
test("simple again", async ({ eq }) => {
const port = 8081;
const { server } = srvd.serve({ port });
const geotiff = await fromUrl(`http://localhost:${port}/data/vestfold.tif`);
const params = {
bbox: [128, 656, 144, 672],
bbox_srs: "simple",
debug_level: 3,
geotiff,
geotiff_srs: "simple",
method: "near-vectorize",
round: false,
tile_array_types: ["Array", "Array", "Array"],
tile_height: 256,
tile_srs: "simple",
tile_layout: "[band][row][column]",
timed: true,
tile_width: 256,
use_overview: true
};
const { height, width, tile, extra } = await createTile(params);
server.close();
const { readResult } = extra;
writeResult(readResult, "simple-again-raw");
// console.log("set of raw values:", new Set(rawdata.flat(1).map(arr => Array.from(arr)).flat(1)));
writeResult({ data: tile }, "simple-again-tile");
});
test("antarctica with NaN", async ({ eq }) => {
const port = 8081;
const { server } = srvd.serve({ port });
const geotiff = await fromUrl(`http://localhost:${port}/data/bremen_sea_ice_conc_2022_9_9.tif`);
const image = await geotiff.getImage();
// [ -3950000, -3943750, 3950000, 4350000 ]
const bbox = image.getBoundingBox();
const params = {
bbox,
bbox_srs: 3031,
debug_level: 3,
geotiff,
method: "near-vectorize",
round: true,
tile_array_types: ["Array", "Array", "Array"],
tile_height: 256,
tile_srs: "EPSG:3031",
tile_layout: "[band][row][column]",
timed: true,
tile_width: 256,
use_overview: true
};
const { height, width, tile, extra } = await createTile(params);
server.close();
const { readResult } = extra;
writeResult(readResult, "bremen_sea_ice_conc_2022_9_9");
});
test("gadas-max", async ({ eq }) => {
const port = 8081;
const { server } = srvd.serve({ port });
const geotiff = await fromUrl(`http://localhost:${port}/data/gadas.tif`);
const params = {
url: "./data/gadas.tif",
bbox: [7_698_736.858, 163_239.838, 10_066_450.246, 1_325_082.668],
bbox_srs: 3857,
debug_level: 0,
geotiff,
method: "max",
round: false,
tile_array_types: ["Uint8Array"],
tile_height: 512,
tile_layout: "[row,column,band]",
tile_srs: 3857,
tile_width: 512,
timed: true,
use_overview: true,
turbo: true
};
const { height, width, tile, extra } = await createTile(params);
server.close();
writeResult({ data: tile, height, width }, "gadas-max");
});