-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
144 lines (125 loc) · 5.03 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chroma-js/chroma.min.js"></script>
<script src="https://unpkg.com/flug/index.js"></script>
<script src="https://unpkg.com/geotiff"></script>
<!-- <script src="https://unpkg.com/geotiff-tile/dist/web/geotiff-tile.min.js"></script> -->
<script src="./dist/web/geotiff-tile.js"></script>
<script>
window.process = {
env: {
// TEST_NAME: "pulling tile from 3-band Geographic GeoTIFF as layout [row][column][band]"
// TEST_NAME: "simple"
}
}
</script>
</head>
<body>
<script>
function three_to_four_bands({ tile, height, width }) {
const data = new Array(4 * height * width).fill(255);
for (let b = 0; b <= 2; b++) {
for (let r = 0; r < height; r++) {
for (let c = 0; c < width; c++) {
data[(r * 4 * width) + (4 * c) + b] = tile[b][r][c];
}
}
}
return data;
}
function three_to_four_bands_b_rc({ tile, height, width }) {
const data = new Array(4 * height * width).fill(255);
for (let b = 0; b <= 2; b++) {
for (let r = 0; r < height; r++) {
for (let c = 0; c < width; c++) {
data[(r * 4 * width) + (4 * c) + b] = tile[b][r * width + c];
}
}
}
return data;
}
function displayTile({ tile, height, width }) {
const data = Uint8ClampedArray.from(tile);
const imageData = new ImageData(data, width, height);
const canvas = document.createElement("CANVAS");
canvas.height = imageData.height;
canvas.width = imageData.width;
const context = canvas.getContext("2d");
context.webkitImageSmoothingEnabled = false;
context.mozImageSmoothingEnabled = false;
context.imageSmoothingEnabled = false;
context.putImageData(imageData, 0, 0);
context.webkitImageSmoothingEnabled = false;
context.mozImageSmoothingEnabled = false;
context.imageSmoothingEnabled = false;
document.body.appendChild(canvas);
canvas.style.background = "darkred";
canvas.style.border = "5px solid chartreuse";
canvas.style.margin = "10px";
canvas.style.height = "512px";
}
test("pulling tile from Harvey COG", async ({ eq }) => {
const url = "https://storage.googleapis.com/pdd-stac/disasters/hurricane-harvey/0831/20170831_172754_101c_3b_Visual.tif";
const geotiff = await GeoTIFF.fromUrl(url);
const { height, width, tile } = await geotiff_tile.createTile({
geotiff,
// mercator tile at x: 956, y: 1695, z: 12
bbox: [-95.976562, 29.535232, -95.888671, 29.611673],
method: "near",
tile_height: 64,
tile_layout: "[band][row][column]",
tile_width: 64,
timed: true,
});
eq(tile[0][0].constructor.name, "Uint8Array");
const data = three_to_four_bands({ height, width, tile })
displayTile({ tile: data, height, width});
});
// test("simple", async ({ eq }) => {
// const url = "./data/gadas.tif";
// const geotiff = await GeoTIFF.fromUrl(url);
// const { height, width, tile } = await geotiff_tile.createTile({
// geotiff,
// bbox: [256, 256, 512, 512],
// bbox_srs: "simple",
// debug_level: 10,
// method: "near",
// tile_height: 512,
// tile_layout: "[band][row][column]",
// tile_width: 512,
// timed: true,
// });
// console.log({height, width, tile});
// console.log("set of values:", new Set(tile.flat(1).map(arr => Array.from(arr)).flat(1)));
// eq(tile[0][0].constructor.name, "Uint8Array");
// const data = three_to_four_bands({ height, width, tile })
// displayTile({ tile: data, height, width});
// });
test("simple", async ({ eq }) => {
const url = "./data/wildfires.tiff";
const geotiff = await GeoTIFF.fromUrl(url);
const image = await geotiff.getImage();
const image_height = image.getHeight(); // 784
const image_width = image.getWidth(); // 1052
const { height, width, tile, extra } = await geotiff_tile.createTile({
geotiff,
bbox: [0, 0, 512, 784 + 200],
bbox_srs: "simple",
debug_level: 10,
method: "near",
tile_height: 512,
tile_layout: "[band][row][column]",
tile_width: 512,
timed: true,
});
const { readResult } = extra;
const rawdata = three_to_four_bands_b_rc({ height: readResult.height, width: readResult.width, tile: readResult.data });
displayTile({ height: extra.readResult.height, width: extra.readResult.width, tile: rawdata });
eq(tile[0][0].constructor.name, "Uint8Array");
const data = three_to_four_bands({ height, width, tile })
displayTile({ tile: data, height, width});
});
</script>
</body>
</html>