Skip to content

Commit

Permalink
added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Jan 15, 2020
1 parent dd2ae81 commit c824b70
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ async function getStats(image){
const decoder = getDecoder(fd);
const tile = await image.getTileOrStrip(colIndex, rowIndex, bandIndex, decoder);
const dataView = new DataView(tile.data);
const { byteLength } = dataView;
for (let y = 0; y < tileHeight; y++) {
for (let x = 0; x < tileWidth; x++) {
const pixelOffset = ((y * tileWidth) + x) * bytesPerPixel;
const value = reader.call(
dataView, pixelOffset + srcSampleOffsets[bandIndex], image.littleEndian,
);
if (value != noDataValue && !isNaN(value)) {
if (typeof min === 'undefined' || value < min) min = value;
else if (typeof max === 'undefined' || value > max) max = value;

const byteOffset = pixelOffset + srcSampleOffsets[bandIndex];
if (byteOffset >= byteLength) {
/* we've reached the end of this row,
so we can continue to the next row */
continue;
} else {
const value = reader.call(dataView, byteOffset, image.littleEndian);
if (value != noDataValue && !isNaN(value)) {
if (typeof min === 'undefined' || value < min) min = value;
else if (typeof max === 'undefined' || value > max) max = value;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/data/setup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# files used by georaster for testing
wget https://geotiff-stats.s3.amazonaws.com/GeogToWGS84GeoKey5.tif -O GeogToWGS84GeoKey5.tif

# files used by geotiff.js for testing
wget https://github.com/EOxServer/autotest/raw/f8d9f4bde6686abbda09c711d4bf5239f5378aa9/autotest/data/meris/MER_FRS_1P_reduced/ENVISAT-MER_FRS_1PNPDE20060816_090929_000001972050_00222_23322_0058_uint16_reduced_compressed.tif -O initial.tiff

Expand Down
37 changes: 17 additions & 20 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,45 @@ const { getStats } = require('../index.js');

const SECONDS_TO_MILLISECONDS = 1000;

describe("GeoTIFF.js Test Data", function() {
this.timeout(50 * SECONDS_TO_MILLISECONDS);
it('GeoTIFF without Statistics', async function() {
const data = readFileSync('./test/data/initial.tiff');
async function getStatsFromFilepath(filepath) {
const data = readFileSync(filepath);
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
const geotiff = await fromArrayBuffer(arrayBuffer);
const image = await geotiff.getImage();
const { bands } = await getStats(image, true);
return await getStats(image, true);
}

describe("GeoTIFF.js Test Data", function() {
this.timeout(50 * SECONDS_TO_MILLISECONDS);
it('GeoTIFF without Statistics', async function() {
const { bands } = await getStatsFromFilepath('./test/data/initial.tiff');
expect(bands[0].min).to.equal(0);
expect(bands[0].max).to.equal(65507);
});
it('GeoTIFF with Statistics', async function() {
const data = readFileSync('./test/data/stats.tiff');
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
const geotiff = await fromArrayBuffer(arrayBuffer);
const image = await geotiff.getImage();
const { bands } = await getStats(image, true);
const { bands } = await getStatsFromFilepath('./test/data/initial.tiff');
expect(bands[0].min).to.equal(0);
expect(bands[0].max).to.equal(65507);
});
it('GeoTIFF with Color Palette', async function() {
const { bands } = await getStatsFromFilepath('./test/data/GeogToWGS84GeoKey5.tif');
expect(bands[0].min).to.equal(0);
expect(bands[0].max).to.equal(2);
})
});

describe("Landsat Data", function() {
this.timeout(5 * SECONDS_TO_MILLISECONDS);
it('should get stats for Landsat Scene', async function() {
const data = readFileSync('./test/data/LC80120312013106LGN01_B6.tif');
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
const geotiff = await fromArrayBuffer(arrayBuffer);
const image = await geotiff.getImage();
const { bands } = await getStats(image, true);
const { bands } = await getStatsFromFilepath('./test/data/LC80120312013106LGN01_B6.tif');
expect(bands[0].min).to.equal(0);
expect(bands[0].max).to.equal(62196);
});
});

describe("GHSL Data", function() {
it('should get stats for worldwide GHSL', async function() {
const data = readFileSync('./test/data/GHS_POP_E2015_GLOBE_R2019A_54009_250_V1_0.tif');
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
const geotiff = await fromArrayBuffer(arrayBuffer);
const image = await geotiff.getImage();
const { bands } = await getStats(image, true);
const { bands } = await getStatsFromFilepath('./test/data/GHS_POP_E2015_GLOBE_R2019A_54009_250_V1_0.tif');
expect(bands[0].min).to.equal(0);
expect(bands[0].max).to.equal(442590.9375 );
});
Expand Down

0 comments on commit c824b70

Please sign in to comment.