Skip to content

Commit

Permalink
feat: expose gdal's NO_DATA as a getter on the image (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha authored Nov 26, 2023
1 parent 44757e5 commit fc21a30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/__test__/cog.read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ describe('CogRead', () => {
assert.equal(im.value(TiffTag.SampleFormat), SampleFormat.Float);
assert.equal(im.value(TiffTag.Photometric), Photometric.MinIsBlack);

assert.equal(im.value(TiffTag.GdalNoData), '-9999');
assert.equal(im.noData, -9999);

assert.equal(im.tagsGeo.get(TiffTagGeo.GTCitationGeoKey), 'NZGD2000 / New Zealand Transverse Mercator 2000');
assert.equal(im.tagsGeo.get(TiffTagGeo.GeodeticCitationGeoKey), 'NZGD2000');
assert.deepEqual(await im.fetch(TiffTag.StripByteCounts), [8064, 8064, 8064, 8064, 8064, 8064, 8064, 5040]);
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/tiff.image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ export class TiffImage {
return this.tagsGeo.get(tag) as TiffTagGeoType[T];
}

/**
* Load and parse the GDAL_NODATA Tifftag
*
* @throws if the tag is not loaded
* @returns null if the tag does not exist
*/
get noData(): number | null {
const tag = this.tags.get(TiffTag.GdalNoData);
if (tag == null) return null;
if (tag.value) return Number(tag.value);
throw new Error('GdalNoData tag is not loaded');
}

/**
* Load and unpack the GeoKeyDirectory
*
Expand Down

0 comments on commit fc21a30

Please sign in to comment.