@@ -7,6 +7,11 @@ const SECONDS_TO_MILLISECONDS = 1000;
7
7
8
8
async function getStatsFromFilepath ( filepath , debug = false ) {
9
9
const data = readFileSync ( filepath ) ;
10
+
11
+ if ( data . byteLength === 0 ) {
12
+ throw new Error ( "This file has 0 bytes: " + filepath ) ;
13
+ }
14
+
10
15
const arrayBuffer = data . buffer . slice ( data . byteOffset , data . byteOffset + data . byteLength ) ;
11
16
const geotiff = await fromArrayBuffer ( arrayBuffer ) ;
12
17
const image = await geotiff . getImage ( ) ;
@@ -42,12 +47,22 @@ describe("GeoTIFF.js Test Data", function() {
42
47
} ) ;
43
48
44
49
describe ( "Landsat Data" , function ( ) {
45
- it ( 'should get stats for downloaded Landsat Scene' , async function ( ) {
50
+ it ( 'should get stats for old downloaded Landsat Scene' , async function ( ) {
46
51
this . timeout ( 20 * SECONDS_TO_MILLISECONDS ) ;
47
- const { bands } = await getStatsFromFilepath ( './test/data/LC80120312013106LGN01_B6.tif' ) ;
52
+ const debug = false ;
53
+ const { bands } = await getStatsFromFilepath ( './test/data/LC80120312013106LGN01_B6.tif' , debug ) ;
48
54
expect ( bands [ 0 ] . min ) . to . equal ( 0 ) ;
49
55
expect ( bands [ 0 ] . max ) . to . equal ( 62196 ) ;
50
56
} ) ;
57
+ it ( 'should get stats for newer downloaded Landsat Scene' , async function ( ) {
58
+ this . timeout ( 20 * SECONDS_TO_MILLISECONDS ) ;
59
+ const debug = false ;
60
+ const { bands } = await getStatsFromFilepath ( './test/data/LC08_L1TP_024030_20180723_20180731_01_T1_B1.TIF' , debug ) ;
61
+ expect ( bands [ 0 ] . min ) . to . equal ( 0 ) ;
62
+ // this gives different results than GDAL, but is consistent with rasterio
63
+ // import rasterio; rasterio.open("./test/data/LC08_L1TP_024030_20180723_20180731_01_T1_B1.TIF").read()[0].max()
64
+ expect ( bands [ 0 ] . max ) . to . equal ( 54590 ) ;
65
+ } ) ;
51
66
it ( 'should get stats for online Landsat Scene with overview file' , async function ( ) {
52
67
this . timeout ( 20 * SECONDS_TO_MILLISECONDS ) ;
53
68
const debug = false ;
0 commit comments