Skip to content

Commit 241c8ad

Browse files
committed
prototype
1 parent 77d7db5 commit 241c8ad

File tree

11 files changed

+2501
-0
lines changed

11 files changed

+2501
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
data/LC*
107+
data/.DS_Store

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1+
:warning: This package is under development. Please report an issues here: https://github.com/geotiff/is-cog/issues
12
# is-cog
23
Super Light and Fast Method for Checking if a TIFF is a Cloud Optimized GeoTIFF
4+
5+
# how does it work
6+
1. It uses [id-tif](https://github.com/DanielJDufour/id-tif) to check if the file is a TIFF.
7+
2. If it is a TIFF, it uses [is-geotiff](https://github.com/GeoTIFF/is-geotiff) to check if the file is a GeoTIFF.
8+
3. If it is a GeoTIFF, it checks if the bytes associated with the following tags are present: TileWidth, TileLength, TileOffsets, and TileByteCounts.
9+
10+
# install
11+
```bash
12+
npm install is-cog
13+
```
14+
15+
# usage
16+
```js
17+
const fs = require("fs");
18+
const isCOG = require("is-cog");
19+
20+
const buffer = fs.readFileSync("./landsat_scene.tiff");
21+
22+
const { is_cog, is_geotiff, is_tiff } = isCOG({
23+
data: buffer,
24+
debug: false // set debug to true for increased logging
25+
});
26+
// is_cog is true
27+
// is_geotiff is true
28+
// is_tiff is true
29+
```

data/cog.tif

1 MB
Binary file not shown.

data/flower.jpg

28.4 KB
Loading

data/flower.tif

469 KB
Binary file not shown.

data/geo.tif

92.6 KB
Binary file not shown.

data/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh -e
2+
3+
wget https://landsat-pds.s3.amazonaws.com/c1/L8/024/030/LC08_L1TP_024030_20180723_20180731_01_T1/LC08_L1TP_024030_20180723_20180731_01_T1_B4.TIF

is-cog.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const idTIF = require("id-tif");
2+
const isGeoTIFF = require("is-geotiff");
3+
const hasBytes = require("has-bytes");
4+
5+
module.exports = function isCOG({ data, debug, is_geotiff, is_tiff }) {
6+
if (debug) console.log("[is-cog] starting with data", data);
7+
8+
if (is_tiff === undefined) is_tiff = idTIF(data, debug);
9+
10+
// return early if not a TIFF file
11+
if (!is_tiff) {
12+
if (debug) console.log("file is not a tiff, so returning early");
13+
return { is_cog: false, is_geotiff: false, is_tiff };
14+
}
15+
16+
if (is_geotiff === undefined) is_geotiff = isGeoTIFF({ data, debug }).result;
17+
18+
// return early if not a GeoTIFF file
19+
if (!is_geotiff) {
20+
if (debug) console.log("file is not a geotiff, so returning early");
21+
return { is_cog: false, is_geotiff, is_tiff };
22+
}
23+
24+
const { result } = hasBytes({
25+
data,
26+
debug,
27+
sequences: {
28+
TileWidth: [66, 1], // 0x0142
29+
TileLength: [67, 1], // 0x0143
30+
TileOffsets: [68, 1], // 0x0144
31+
TileByteCounts: [69, 1] // 0x0145
32+
}
33+
});
34+
35+
return { is_cog: result, is_geotiff, is_tiff };
36+
};

0 commit comments

Comments
 (0)