Skip to content

Commit 585bc03

Browse files
committed
added tests for getGDALMetadata
1 parent bcd8790 commit 585bc03

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

test/data/setup_data.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ done
7979
gdal_translate -of GTiff -co NBITS=16 -ot Float32 initial.tiff float_n_bit_16.tiff || true
8080
gdal_translate -of GTiff -co NBITS=16 -ot Float32 -co TILED=YES initial.tiff float_n_bit_tiled_16.tiff || true
8181
gdal_translate -of GTiff -co NBITS=16 -ot Float32 -co INTERLEAVE=BAND initial.tiff float_n_bit_interleave_16.tiff || true
82+
83+
# GDAL_METADATA support
84+
wget https://github.com/GeoTIFF/test-data/archive/refs/heads/main.zip -O geotiff-test-data.zip
85+
unzip -j -o geotiff-test-data.zip "test-data-main/files/*" -d .
86+
rm geotiff-test-data.zip

test/geotiff.spec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,73 @@ describe('Geo metadata tests', async () => {
529529
});
530530
});
531531

532+
describe("GDAL_METADATA tests", async () => {
533+
it('should parse stats for specific sample', async () => {
534+
const tiff = await GeoTIFF.fromSource(createSource('abetow-ERD2018-EBIRD_SCIENCE-20191109-a5cf4cb2_hr_2018_abundance_median.tiff'));
535+
const image = await tiff.getImage();
536+
const metadata = await image.getGDALMetadata(10);
537+
expect(metadata).to.deep.equal({
538+
STATISTICS_MAXIMUM: '7.2544522285461',
539+
STATISTICS_MEAN: 'nan',
540+
STATISTICS_MINIMUM: '0',
541+
STATISTICS_STDDEV: 'nan'
542+
});
543+
});
544+
545+
it('should parse stats for single-band GeoTIFF', async () => {
546+
const tiff = await GeoTIFF.fromSource(createSource('nt_20201024_f18_nrt_s.tif'));
547+
const image = await tiff.getImage();
548+
const metadata = await image.getGDALMetadata();
549+
expect(metadata).to.deep.equal({
550+
STATISTICS_MAXIMUM: '100',
551+
STATISTICS_MEAN: '28.560288669249',
552+
STATISTICS_MINIMUM: '0',
553+
STATISTICS_STDDEV: '39.349526064368'
554+
});
555+
});
556+
557+
it('should parse layer type', async () => {
558+
const tiff = await GeoTIFF.fromSource(createSource('eu_pasture.tiff'));
559+
const image = await tiff.getImage();
560+
const metadata = await image.getGDALMetadata();
561+
expect(metadata).to.deep.equal({
562+
LAYER_TYPE: 'athematic'
563+
});
564+
});
565+
566+
it('should parse color interpretation', async () => {
567+
const tiff = await GeoTIFF.fromSource(createSource('utm.tif'));
568+
const image = await tiff.getImage();
569+
const metadata = await image.getGDALMetadata();
570+
expect(metadata).to.deep.equal({
571+
COLORINTERP: 'Palette'
572+
});
573+
});
574+
575+
it('should parse stats for another single-band GeoTIFF', async () => {
576+
const tiff = await GeoTIFF.fromSource(createSource('vestfold.tif'));
577+
const image = await tiff.getImage();
578+
const metadata = await image.getGDALMetadata();
579+
expect(metadata).to.deep.equal({
580+
STATISTICS_MAXIMUM: '332.6073328654',
581+
STATISTICS_MEAN: '83.638959236148',
582+
STATISTICS_MINIMUM: '18.103807449341',
583+
STATISTICS_STDDEV: '69.590554367352'
584+
});
585+
});
586+
587+
it('should parse creation times', async () => {
588+
const tiff = await GeoTIFF.fromSource(createSource('wind_direction.tif'));
589+
const image = await tiff.getImage();
590+
const metadata = await image.getGDALMetadata();
591+
expect(metadata).to.deep.equal({
592+
creationTime: '1497289465',
593+
creationTimeString: '2017-06-12T17:44:25.466257Z',
594+
name: 'Wind_Dir_SFC'
595+
});
596+
});
597+
});
598+
532599
describe('COG tests', async () => {
533600
it('should parse the header ghost area when present', async () => {
534601
const tiff = await GeoTIFF.fromSource(createSource('cog.tiff'));

0 commit comments

Comments
 (0)