Skip to content

Commit

Permalink
doc: tag access via .value() and .valueGeo() (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha authored Nov 26, 2023
1 parent fc21a30 commit 70992a2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const cog = await Tiff.create(source);
const img = cog.images[0];
if (img.isTiled()) throw new Error('Tiff is not tiled');
const tile = await img.getTile(2, 2); // Fetch a tile from a tiff x:2, y:2

// Tiff tags can be access too
img.value(TiffTag.GdalNoData); // "-9999"
// or tag metadata can be accessed
img.tags.get(TiffTag.GdalNoData);
```

## Command Line Interface
Expand Down
19 changes: 19 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,27 @@ if (img.isTiled()) {
const origin = img.origin;
/** Bounding box of the tiff */
const bbox = img.bbox;

// Tiff tags can be accessed via some helpers
const noData = img.noData; // -9999
const noDataTag = img.tags.get(TiffTag.GdalNoData) // Tag information
const noDataValue = img.value(TiffTag.GdalNoData) // "-9999" (tag is stored as a string)
```

### Tags

Some tags have exported constants to make them easier to work with

```typescript
const photometric = img.value(TiffTag.Photometric)

if( photometric == Photometric.Rgb) {
// Tiff is a RGB photometric tiff
}
```

For a full list see [./src/index.ts](./src/index.ts)


More examples can bee seen

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/__test__/cog.read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ describe('CogRead', () => {
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.equal(im.valueGeo(TiffTagGeo.GTCitationGeoKey), 'NZGD2000 / New Zealand Transverse Mercator 2000');
assert.equal(im.valueGeo(TiffTagGeo.GeodeticCitationGeoKey), 'NZGD2000');
assert.deepEqual(await im.fetch(TiffTag.StripByteCounts), [8064, 8064, 8064, 8064, 8064, 8064, 8064, 5040]);
});

Expand Down Expand Up @@ -125,6 +125,6 @@ describe('CogRead', () => {
'ProjLinearUnitsGeoKey',
]);

assert.deepEqual(im.tagsGeo.get(TiffTagGeo.GeogTOWGS84GeoKey), [0, 0, 0, 0, 0, 0, 0]);
assert.deepEqual(im.valueGeo(TiffTagGeo.GeogTOWGS84GeoKey), [0, 0, 0, 0, 0, 0, 0]);
});
});
2 changes: 1 addition & 1 deletion packages/core/src/tiff.image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class TiffImage {
*
* @example
* ```typescript
* img.fetch(TiffTag.ImageWidth) // 512 (px)
* await img.fetch(TiffTag.ImageWidth) // 512 (px)
* ```
*
* @param tag tag to fetch
Expand Down

0 comments on commit 70992a2

Please sign in to comment.