Decoding the GeoTIFF

Process to Decode GeoTIFF and Retrieve Tile

1
// bbox that is sent from client
2
const request = [
3
-28493.166784412522,
4
4224973.143255847,
5
2358.211624949061,
6
4255884.5438021915
7
];
8
9
// convert to window to round to nearest tile size
10
const targetWindow: ImageMetadata = await GeoUtils.bboxtoWindow(max_window, max_bbox, request);
11
12
// Use GetGeoTile to obtain the tile that you would like
13
const tiff_of_tile = await getGeoTile(ipfs, cid, ires.max_Dimensions);
Copied!

Using IPLD to resolve tile paths

We used the interface-ipld-format to figure out the utility functions for the IPLD Blocks. The following utility function in the js-ipld-dag-cbor package is:
const iter = await dagCBOR.resolver.tree(block.data);
The iterator iter contained all possible paths , in the object to outline the tree. In order to access the serialized binary of the tile, we just have to use the corresponding path with its respective /data tag.
1
[
2
'0,0,240,240',
3
'0,0,240,240/cid',
4
'0,0,240,240/data',
5
'0,0,240,240/window',
6
'0,0,240,240/window/0',
7
'0,0,240,240/window/1',
8
'0,0,240,240/window/2',
9
'0,0,240,240/window/3',
10
'0,0,240,240/tileSize',
11
'0,0,240,240/tileSize/width',
12
'0,0,240,240/tileSize/height',
13
...
14
...
15
'240,240,480,480',
16
'240,240,480,480/cid',
17
'240,240,480,480/data',
18
'240,240,480,480/window',
19
'240,240,480,480/window/0',
20
'240,240,480,480/window/1',
21
'240,240,480,480/window/2',
22
'240,240,480,480/window/3',
23
'240,240,480,480/tileSize',
24
'240,240,480,480/tileSize/width',
25
'240,240,480,480/tileSize/height',
26
'480,240,514,480',
27
'480,240,514,480/cid',
28
'480,240,514,480/data',
29
'480,240,514,480/window',
30
'480,240,514,480/window/0',
31
'480,240,514,480/window/1',
32
'480,240,514,480/window/2',
33
'480,240,514,480/window/3',
34
'480,240,514,480/tileSize',
35
'480,240,514,480/tileSize/width',
36
'480,240,514,480/tileSize/height'
37
]
Copied!
Using resolver.resolve(binaryBlob, path) ,another utility function, we can take one of the paths in the Array and use it to query the data we need.
const path = '0,240,240,480/data';
const result = await dagCBOR.resolver.resolve(binary, path);
If we pass in a path with a /data tag, the deserialized binary will represent the source raw binary of the tile. The serialized binary data of the Tile that we encoded earlier.
1
<Buffer 81 59 e1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 57554 more bytes>
Copied!
We need to deserialize the binary data in order to get back the source binary.
const raw_binary = await dagCBOR.util.deserialize(tile_binary.value);
1
[
2
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 57550 more bytes>
3
]
Copied!
After we get the data back to source binary we can use the binary data and some metadata in to write back into a TIFF, with writeArrayBuffer:
1
ArrayBuffer {
2
[Uint8Contents]: <4d 4d 00 2a 00 00 00 08 00 18 01 00 00 03 00 00 00 01 00 f0 00 00 01 01 00 03 00 00 00 01 00 f0 00 00 01 02 00 03 00 00 00 01 00 08 00 00 01 03 00 03 00 00 00 01 00 01 00 00 01 06 00 03 00 00 00 01 00 01 00 00 01 11 00 04 00 00 00 01 00 00 03 e8 01 15 00 03 00 00 00 01 00 01 00 00 01 16 00 04 00 00 ... 58500 more bytes>,
3
byteLength: 58600
4
}
Copied!
Last modified 6mo ago