Skip to main content

Class: GeoTIFF

Defined in: geotiff.ts:35

A high-level GeoTIFF abstraction built on @cogeotiff/core's Tiff and TiffImage classes.

This class separates data IFDs from mask IFDs, pairs them by resolution level, and exposes sorted overviews. Intentionally mirrors the Python async-geotiff API as closely as possible.

Construct via GeoTIFF.fromUrl, GeoTIFF.fromArrayBuffer, GeoTIFF.open or GeoTIFF.fromTiff.

See

Overview for reduced-resolution overview images.

Properties

cachedTags

readonly cachedTags: CachedTags

Defined in: geotiff.ts:48

Cached TIFF tags that are pre-fetched when opening the GeoTIFF.


dataSource

readonly dataSource: Pick<Source, "fetch">

Defined in: geotiff.ts:56

The data source used for fetching tile data.

This is typically the raw source (e.g. HTTP or memory) rather than a layered source with caching and chunking, to avoid unnecessary copying of tile data through cache layers.


gdalMetadata

readonly gdalMetadata: GDALMetadata | null

Defined in: geotiff.ts:71

Parsed GDALMetadata tag, if present.


gkd

readonly gkd: GeoKeyDirectory

Defined in: geotiff.ts:68

The GeoKeyDirectory of the primary IFD.


image

readonly image: TiffImage

Defined in: geotiff.ts:62

The primary (full-resolution) TiffImage.


maskImage

readonly maskImage: TiffImage | null

Defined in: geotiff.ts:65

The mask IFD of the full-resolution GeoTIFF, if any.


overviews

readonly overviews: Overview[]

Defined in: geotiff.ts:42

Reduced-resolution overview levels, sorted finest-to-coarsest.

Does not include the full-resolution image — use fetchTile on the GeoTIFF instance itself for that.


tiff

readonly tiff: Tiff

Defined in: geotiff.ts:59

The underlying Tiff instance.

Accessors

bbox

Get Signature

get bbox(): [number, number, number, number]

Defined in: geotiff.ts:358

Bounding box [minX, minY, maxX, maxY] in the CRS.

Returns

[number, number, number, number]


count

Get Signature

get count(): number

Defined in: geotiff.ts:353

Number of bands (samples per pixel).

Returns

number


crs

Get Signature

get crs(): number | ProjJson

Defined in: geotiff.ts:279

The CRS parsed from the GeoKeyDirectory.

Returns an EPSG code (number) for EPSG-coded CRSes, or a PROJJSON object for user-defined CRSes. The result is cached after the first access.

See also GeoTIFF.epsg for the EPSG code directly from the TIFF tags.

Returns

number | ProjJson


height

Get Signature

get height(): number

Defined in: geotiff.ts:292

Image height in pixels.

Returns

number


isTiled

Get Signature

get isTiled(): boolean

Defined in: geotiff.ts:317

Whether the primary image is tiled.

Returns

boolean


nodata

Get Signature

get nodata(): number | null

Defined in: geotiff.ts:312

The no data value, or null if not set.

Returns

number | null


offsets

Get Signature

get offsets(): number[]

Defined in: geotiff.ts:339

The offset for each band (0-indexed), defaulting to 0.

Extracted from the GDALMetadata TIFF tag.

Returns

number[]


scales

Get Signature

get scales(): number[]

Defined in: geotiff.ts:348

The scale for each band (0-indexed), defaulting to 1.

Extracted from the GDALMetadata TIFF tag.

Returns

number[]


storedStats

Get Signature

get storedStats(): ReadonlyMap<number, BandStatistics> | null

Defined in: geotiff.ts:329

The pre-existing statistics for each band, if available.

Extracted from the GDALMetadata TIFF tag; never computed on demand. Keys are 1-based band indices to match GDAL's convention.

Returns null if no statistics are stored in the file.

Returns

ReadonlyMap<number, BandStatistics> | null


tileCount

Get Signature

get tileCount(): TiffImageTileCount

Defined in: geotiff.ts:297

The number of tiles in the x and y directions

Returns

TiffImageTileCount


tileHeight

Get Signature

get tileHeight(): number

Defined in: geotiff.ts:307

Tile height in pixels.

Returns

number


tileWidth

Get Signature

get tileWidth(): number

Defined in: geotiff.ts:302

Tile width in pixels.

Returns

number


transform

Get Signature

get transform(): Affine

Defined in: geotiff.ts:365

Return the dataset's georeferencing transformation matrix.

Returns

Affine


width

Get Signature

get width(): number

Defined in: geotiff.ts:287

Image width in pixels.

Returns

number

Methods

fetchTile()

fetchTile(x, y, options?): Promise<Tile>

Defined in: geotiff.ts:387

Fetch a single tile from the full-resolution image.

Parameters

x

number

The tile column index (0-based).

y

number

The tile row index (0-based).

options?

Optional parameters for fetching the tile.

boundless?

boolean

Whether to clip tiles that are partially outside the image bounds. When true, no clipping is applied. Defaults to true.

pool?

DecoderPool

An optional DecoderPool for decoding the tile data. If not provided, a new decoder will be created for each tile.

signal?

AbortSignal

An optional AbortSignal to cancel the fetch request.

Returns

Promise<Tile>


index()

index(x, y, op?): [number, number]

Defined in: geotiff.ts:410

Get the (row, col) pixel index containing the geographic coordinate (x, y).

Parameters

x

number

x coordinate in the CRS.

y

number

y coordinate in the CRS.

op?

(n) => number

Rounding function applied to fractional pixel indices. Defaults to Math.floor.

Returns

[number, number]

[row, col] pixel indices.


xy()

xy(row, col, offset?): [number, number]

Defined in: geotiff.ts:426

Get the geographic (x, y) coordinate of the pixel at (row, col).

Parameters

row

number

Pixel row.

col

number

Pixel column.

offset?

Which part of the pixel to return. Defaults to "center".

"center" | "ul" | "ur" | "ll" | "lr"

Returns

[number, number]

[x, y] in the CRS.


fromArrayBuffer()

static fromArrayBuffer(input): Promise<GeoTIFF>

Defined in: geotiff.ts:215

Create a GeoTIFF from an ArrayBuffer containing the entire file.

This is a convenience method that wraps the ArrayBuffer in a memory source and calls GeoTIFF.open. For large files, consider using GeoTIFF.fromUrl or GeoTIFF.open with a chunked HTTP source to avoid loading the entire file into memory at once.

Parameters

input

ArrayBuffer

The ArrayBuffer containing the GeoTIFF file data.

Returns

Promise<GeoTIFF>

A Promise that resolves to a GeoTIFF instance.


fromTiff()

static fromTiff(tiff, dataSource): Promise<GeoTIFF>

Defined in: geotiff.ts:122

Create a GeoTIFF from an already-initialised Tiff instance.

All IFDs are walked; mask IFDs are matched to data IFDs by matching (width, height). Overviews are sorted from finest to coarsest resolution.

Parameters

tiff

Tiff

dataSource

Pick<Source, "fetch">

A source for fetching tile data. This is separate from the source used to construct the TIFF to allow for separate caching implementations.

Returns

Promise<GeoTIFF>


fromUrl()

static fromUrl(url, options?): Promise<GeoTIFF>

Defined in: geotiff.ts:232

Create a new GeoTIFF from a URL.

Parameters

url

The URL of the GeoTIFF to open.

string | URL

options?

Optional parameters for chunk size and cache size.

cacheSize?

number = ...

The size of the cache for recently accessed header chunks. Currently no caching is applied to data fetches. Defaults to 1MB.

chunkSize?

number = ...

The minimum size for each request made to the source while reading header metadata. Defaults to 32KB.

Returns

Promise<GeoTIFF>

A Promise that resolves to a GeoTIFF instance.


open()

static open(options): Promise<GeoTIFF>

Defined in: geotiff.ts:102

Open a GeoTIFF from a @cogeotiff/core Source.

This creates and initialises the underlying Tiff, then classifies IFDs.

Parameters

options
dataSource

Pick<Source, "fetch">

A source for fetching tile data. This is separate from the source used to construct the TIFF to allow for separate caching implementations.

headerSource

Source

The source used to construct the TIFF. This is typically a layered source with caching and chunking, to optimise access to TIFF tags and IFDs.

prefetch?

number

Number of bytes to prefetch when reading TIFF tags and IFDs. Defaults to 32KB, which is enough for most tags and small IFDs. Increase if you have many tags or large IFDs.

Returns

Promise<GeoTIFF>