@@ -5,48 +5,45 @@ const { getStats } = require('../index.js');
5
5
6
6
const SECONDS_TO_MILLISECONDS = 1000 ;
7
7
8
- describe ( "GeoTIFF.js Test Data" , function ( ) {
9
- this . timeout ( 50 * SECONDS_TO_MILLISECONDS ) ;
10
- it ( 'GeoTIFF without Statistics' , async function ( ) {
11
- const data = readFileSync ( './test/data/initial.tiff' ) ;
8
+ async function getStatsFromFilepath ( filepath ) {
9
+ const data = readFileSync ( filepath ) ;
12
10
const arrayBuffer = data . buffer . slice ( data . byteOffset , data . byteOffset + data . byteLength ) ;
13
11
const geotiff = await fromArrayBuffer ( arrayBuffer ) ;
14
12
const image = await geotiff . getImage ( ) ;
15
- const { bands } = await getStats ( image , true ) ;
13
+ return await getStats ( image , true ) ;
14
+ }
15
+
16
+ describe ( "GeoTIFF.js Test Data" , function ( ) {
17
+ this . timeout ( 50 * SECONDS_TO_MILLISECONDS ) ;
18
+ it ( 'GeoTIFF without Statistics' , async function ( ) {
19
+ const { bands } = await getStatsFromFilepath ( './test/data/initial.tiff' ) ;
16
20
expect ( bands [ 0 ] . min ) . to . equal ( 0 ) ;
17
21
expect ( bands [ 0 ] . max ) . to . equal ( 65507 ) ;
18
22
} ) ;
19
23
it ( 'GeoTIFF with Statistics' , async function ( ) {
20
- const data = readFileSync ( './test/data/stats.tiff' ) ;
21
- const arrayBuffer = data . buffer . slice ( data . byteOffset , data . byteOffset + data . byteLength ) ;
22
- const geotiff = await fromArrayBuffer ( arrayBuffer ) ;
23
- const image = await geotiff . getImage ( ) ;
24
- const { bands } = await getStats ( image , true ) ;
24
+ const { bands } = await getStatsFromFilepath ( './test/data/initial.tiff' ) ;
25
25
expect ( bands [ 0 ] . min ) . to . equal ( 0 ) ;
26
26
expect ( bands [ 0 ] . max ) . to . equal ( 65507 ) ;
27
27
} ) ;
28
+ it ( 'GeoTIFF with Color Palette' , async function ( ) {
29
+ const { bands } = await getStatsFromFilepath ( './test/data/GeogToWGS84GeoKey5.tif' ) ;
30
+ expect ( bands [ 0 ] . min ) . to . equal ( 0 ) ;
31
+ expect ( bands [ 0 ] . max ) . to . equal ( 2 ) ;
32
+ } )
28
33
} ) ;
29
34
30
35
describe ( "Landsat Data" , function ( ) {
31
36
this . timeout ( 5 * SECONDS_TO_MILLISECONDS ) ;
32
37
it ( 'should get stats for Landsat Scene' , async function ( ) {
33
- const data = readFileSync ( './test/data/LC80120312013106LGN01_B6.tif' ) ;
34
- const arrayBuffer = data . buffer . slice ( data . byteOffset , data . byteOffset + data . byteLength ) ;
35
- const geotiff = await fromArrayBuffer ( arrayBuffer ) ;
36
- const image = await geotiff . getImage ( ) ;
37
- const { bands } = await getStats ( image , true ) ;
38
+ const { bands } = await getStatsFromFilepath ( './test/data/LC80120312013106LGN01_B6.tif' ) ;
38
39
expect ( bands [ 0 ] . min ) . to . equal ( 0 ) ;
39
40
expect ( bands [ 0 ] . max ) . to . equal ( 62196 ) ;
40
41
} ) ;
41
42
} ) ;
42
43
43
44
describe ( "GHSL Data" , function ( ) {
44
45
it ( 'should get stats for worldwide GHSL' , async function ( ) {
45
- const data = readFileSync ( './test/data/GHS_POP_E2015_GLOBE_R2019A_54009_250_V1_0.tif' ) ;
46
- const arrayBuffer = data . buffer . slice ( data . byteOffset , data . byteOffset + data . byteLength ) ;
47
- const geotiff = await fromArrayBuffer ( arrayBuffer ) ;
48
- const image = await geotiff . getImage ( ) ;
49
- const { bands } = await getStats ( image , true ) ;
46
+ const { bands } = await getStatsFromFilepath ( './test/data/GHS_POP_E2015_GLOBE_R2019A_54009_250_V1_0.tif' ) ;
50
47
expect ( bands [ 0 ] . min ) . to . equal ( 0 ) ;
51
48
expect ( bands [ 0 ] . max ) . to . equal ( 442590.9375 ) ;
52
49
} ) ;
0 commit comments