Skip to content

Commit 58bc790

Browse files
Merge pull request #275 from DanielJDufour/issue-264-get-gdal-metadata
issue-264: fixed getGDALMetadata
2 parents 156dd66 + 92144b1 commit 58bc790

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/geotiffimage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,9 @@ class GeoTIFFImage {
783783

784784
let items = findTagsByName(string, 'Item');
785785

786-
if (sample !== null) {
786+
if (sample === null) {
787+
items = items.filter((item) => getAttribute(item, 'sample') === undefined);
788+
} else {
787789
items = items.filter((item) => Number(getAttribute(item, 'sample')) === sample);
788790
}
789791

test/data/setup_data.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,7 @@ gdal_translate -of GTiff -co NBITS=16 -ot Float32 -co INTERLEAVE=BAND initial.ti
8383
# GDAL_METADATA support
8484
wget https://github.com/GeoTIFF/test-data/archive/8ac198032d8b02160049ca161e8108e3d38176f3.zip -O geotiff-test-data.zip
8585
unzip -j -o geotiff-test-data.zip "test-data-*/files/*" -d .
86-
rm geotiff-test-data.zip
86+
rm geotiff-test-data.zip
87+
88+
# add top-level metadata to a tiff for testing purposes
89+
gdal_edit.py -mo DATUM=WGS84 wind_direction.tif

test/geotiff.spec.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ describe('GDAL_METADATA tests', async () => {
558558
it('should parse stats for single-band GeoTIFF', async () => {
559559
const tiff = await GeoTIFF.fromSource(createSource('nt_20201024_f18_nrt_s.tif'));
560560
const image = await tiff.getImage();
561-
const metadata = await image.getGDALMetadata();
562-
expect(metadata).to.deep.equal({
561+
expect(await image.getGDALMetadata(), {}); // no top-level-stats
562+
expect(await image.getGDALMetadata(0)).to.deep.equal({
563563
STATISTICS_MAXIMUM: '100',
564564
STATISTICS_MEAN: '28.560288669249',
565565
STATISTICS_MINIMUM: '0',
@@ -570,7 +570,7 @@ describe('GDAL_METADATA tests', async () => {
570570
it('should parse layer type', async () => {
571571
const tiff = await GeoTIFF.fromSource(createSource('eu_pasture.tiff'));
572572
const image = await tiff.getImage();
573-
const metadata = await image.getGDALMetadata();
573+
const metadata = await image.getGDALMetadata(0);
574574
expect(metadata).to.deep.equal({
575575
LAYER_TYPE: 'athematic',
576576
});
@@ -579,7 +579,7 @@ describe('GDAL_METADATA tests', async () => {
579579
it('should parse color interpretation', async () => {
580580
const tiff = await GeoTIFF.fromSource(createSource('utm.tif'));
581581
const image = await tiff.getImage();
582-
const metadata = await image.getGDALMetadata();
582+
const metadata = await image.getGDALMetadata(0);
583583
expect(metadata).to.deep.equal({
584584
COLORINTERP: 'Palette',
585585
});
@@ -588,7 +588,7 @@ describe('GDAL_METADATA tests', async () => {
588588
it('should parse stats for another single-band GeoTIFF', async () => {
589589
const tiff = await GeoTIFF.fromSource(createSource('vestfold.tif'));
590590
const image = await tiff.getImage();
591-
const metadata = await image.getGDALMetadata();
591+
const metadata = await image.getGDALMetadata(0);
592592
expect(metadata).to.deep.equal({
593593
STATISTICS_MAXIMUM: '332.6073328654',
594594
STATISTICS_MEAN: '83.638959236148',
@@ -600,13 +600,22 @@ describe('GDAL_METADATA tests', async () => {
600600
it('should parse creation times', async () => {
601601
const tiff = await GeoTIFF.fromSource(createSource('wind_direction.tif'));
602602
const image = await tiff.getImage();
603-
const metadata = await image.getGDALMetadata();
603+
const metadata = await image.getGDALMetadata(0);
604604
expect(metadata).to.deep.equal({
605605
creationTime: '1497289465',
606606
creationTimeString: '2017-06-12T17:44:25.466257Z',
607607
name: 'Wind_Dir_SFC',
608608
});
609609
});
610+
611+
it('should parse top-level metadata when no sample is specified', async () => {
612+
const tiff = await GeoTIFF.fromSource(createSource('wind_direction.tif'));
613+
const image = await tiff.getImage();
614+
const metadata = await image.getGDALMetadata();
615+
expect(metadata).to.deep.equal({
616+
DATUM: 'WGS84',
617+
});
618+
});
610619
});
611620

612621
describe('COG tests', async () => {

0 commit comments

Comments
 (0)