@developmentseed/geotiff 0.3.0-beta.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/dist/array.d.ts +12 -27
- package/dist/array.d.ts.map +1 -1
- package/dist/array.js.map +1 -1
- package/dist/codecs/lerc.d.ts +2 -2
- package/dist/codecs/lerc.d.ts.map +1 -1
- package/dist/codecs/lerc.js +23 -2
- package/dist/codecs/lerc.js.map +1 -1
- package/dist/codecs/lzw.d.ts.map +1 -1
- package/dist/codecs/lzw.js +2 -1
- package/dist/codecs/lzw.js.map +1 -1
- package/dist/codecs/predictor.d.ts +1 -2
- package/dist/codecs/predictor.d.ts.map +1 -1
- package/dist/codecs/predictor.js +1 -2
- package/dist/codecs/predictor.js.map +1 -1
- package/dist/codecs/utils.d.ts +2 -0
- package/dist/codecs/utils.d.ts.map +1 -0
- package/dist/codecs/utils.js +11 -0
- package/dist/codecs/utils.js.map +1 -0
- package/dist/codecs/zstd.d.ts +2 -0
- package/dist/codecs/zstd.d.ts.map +1 -0
- package/dist/codecs/zstd.js +7 -0
- package/dist/codecs/zstd.js.map +1 -0
- package/dist/decode.d.ts +32 -6
- package/dist/decode.d.ts.map +1 -1
- package/dist/decode.js +35 -15
- package/dist/decode.js.map +1 -1
- package/dist/fetch.d.ts +6 -2
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.js +178 -34
- package/dist/fetch.js.map +1 -1
- package/dist/gdal-metadata.d.ts +17 -0
- package/dist/gdal-metadata.d.ts.map +1 -0
- package/dist/gdal-metadata.js +59 -0
- package/dist/gdal-metadata.js.map +1 -0
- package/dist/geotiff.d.ts +91 -11
- package/dist/geotiff.d.ts.map +1 -1
- package/dist/geotiff.js +140 -43
- package/dist/geotiff.js.map +1 -1
- package/dist/ifd.d.ts +8 -8
- package/dist/ifd.d.ts.map +1 -1
- package/dist/ifd.js +21 -13
- package/dist/ifd.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/overview.d.ts +33 -3
- package/dist/overview.d.ts.map +1 -1
- package/dist/overview.js +35 -2
- package/dist/overview.js.map +1 -1
- package/dist/pool/pool.d.ts +71 -0
- package/dist/pool/pool.d.ts.map +1 -0
- package/dist/pool/pool.js +100 -0
- package/dist/pool/pool.js.map +1 -0
- package/dist/pool/worker.d.ts +23 -0
- package/dist/pool/worker.d.ts.map +1 -0
- package/dist/pool/worker.js +37 -0
- package/dist/pool/worker.js.map +1 -0
- package/dist/pool/wrapper.d.ts +37 -0
- package/dist/pool/wrapper.d.ts.map +1 -0
- package/dist/pool/wrapper.js +46 -0
- package/dist/pool/wrapper.js.map +1 -0
- package/dist/tile-matrix-set.d.ts.map +1 -1
- package/dist/tile-matrix-set.js +12 -12
- package/dist/tile-matrix-set.js.map +1 -1
- package/dist/transform.d.ts +7 -0
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +40 -1
- package/dist/transform.js.map +1 -1
- package/package.json +18 -12
- package/dist/api.d.ts +0 -34
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -84
- package/dist/api.js.map +0 -1
- package/dist/decode/api.d.ts +0 -28
- package/dist/decode/api.d.ts.map +0 -1
- package/dist/decode/api.js +0 -80
- package/dist/decode/api.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/fetch.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { TiffTag } from "@cogeotiff/core";
|
|
1
|
+
import { Compression, PlanarConfiguration, TiffTag } from "@cogeotiff/core";
|
|
2
2
|
import { compose, translation } from "@developmentseed/affine";
|
|
3
3
|
import { decode } from "./decode.js";
|
|
4
|
-
export async function fetchTile(self, x, y,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
const { bitsPerSample: bitsPerSamples, predictor, planarConfiguration, sampleFormat: sampleFormats, } = self.cachedTags;
|
|
13
|
-
const { bytes, compression } = tile;
|
|
4
|
+
export async function fetchTile(self, x, y, { boundless = true, pool, signal, } = {}) {
|
|
5
|
+
const tileFetch = fetchCogBytes(self, x, y, { signal });
|
|
6
|
+
const maskFetch = self.maskImage != null
|
|
7
|
+
? getTile(self.maskImage, x, y, self.dataSource, { signal })
|
|
8
|
+
: Promise.resolve(null);
|
|
9
|
+
const [tileBytes, maskBytes] = await Promise.all([tileFetch, maskFetch]);
|
|
10
|
+
const { bitsPerSample: bitsPerSamples, predictor, planarConfiguration, sampleFormat: sampleFormats, lercParameters, } = self.cachedTags;
|
|
14
11
|
const { sampleFormat, bitsPerSample } = getUniqueSampleFormat(sampleFormats, bitsPerSamples);
|
|
15
12
|
const tileTransform = compose(self.transform, translation(x * self.tileWidth, y * self.tileHeight));
|
|
16
13
|
const samplesPerPixel = self.image.value(TiffTag.SamplesPerPixel) ?? 1;
|
|
17
|
-
const
|
|
14
|
+
const decoderMetadata = {
|
|
18
15
|
sampleFormat,
|
|
19
16
|
bitsPerSample,
|
|
20
17
|
samplesPerPixel,
|
|
@@ -22,13 +19,20 @@ export async function fetchTile(self, x, y, options = {}) {
|
|
|
22
19
|
height: self.tileHeight,
|
|
23
20
|
predictor,
|
|
24
21
|
planarConfiguration,
|
|
25
|
-
|
|
22
|
+
lercParameters,
|
|
23
|
+
};
|
|
24
|
+
const [decodedPixels, mask] = await Promise.all([
|
|
25
|
+
decodeTile(tileBytes, decoderMetadata, pool),
|
|
26
|
+
maskBytes != null && self.maskImage != null
|
|
27
|
+
? decodeMask(maskBytes, self.maskImage, pool)
|
|
28
|
+
: Promise.resolve(null),
|
|
29
|
+
]);
|
|
26
30
|
const array = {
|
|
27
31
|
...decodedPixels,
|
|
28
32
|
count: samplesPerPixel,
|
|
29
33
|
height: self.tileHeight,
|
|
30
34
|
width: self.tileWidth,
|
|
31
|
-
mask
|
|
35
|
+
mask,
|
|
32
36
|
transform: tileTransform,
|
|
33
37
|
crs: self.crs,
|
|
34
38
|
nodata: self.nodata,
|
|
@@ -36,11 +40,147 @@ export async function fetchTile(self, x, y, options = {}) {
|
|
|
36
40
|
return {
|
|
37
41
|
x,
|
|
38
42
|
y,
|
|
39
|
-
array:
|
|
40
|
-
? clipToImageBounds(self, x, y, array)
|
|
41
|
-
: array,
|
|
43
|
+
array: boundless === true ? array : clipToImageBounds(self, x, y, array),
|
|
42
44
|
};
|
|
43
45
|
}
|
|
46
|
+
async function decodeMask(mask, maskImage, pool) {
|
|
47
|
+
const maskSampleFormats = maskImage.value(TiffTag.SampleFormat) ?? [1];
|
|
48
|
+
const maskBitsPerSample = maskImage.value(TiffTag.BitsPerSample) ?? [8];
|
|
49
|
+
const { sampleFormat, bitsPerSample } = getUniqueSampleFormat(maskSampleFormats, new Uint16Array(maskBitsPerSample));
|
|
50
|
+
const { width, height } = maskImage.tileSize;
|
|
51
|
+
const metadata = {
|
|
52
|
+
sampleFormat,
|
|
53
|
+
bitsPerSample,
|
|
54
|
+
samplesPerPixel: maskImage.value(TiffTag.SamplesPerPixel) ?? 1,
|
|
55
|
+
width,
|
|
56
|
+
height,
|
|
57
|
+
predictor: maskImage.value(TiffTag.Predictor) ?? 1,
|
|
58
|
+
planarConfiguration: maskImage.value(TiffTag.PlanarConfiguration) ??
|
|
59
|
+
PlanarConfiguration.Contig,
|
|
60
|
+
};
|
|
61
|
+
const decoderFn = (bytes, compression, meta) => pool
|
|
62
|
+
? pool.decode(bytes, compression, meta)
|
|
63
|
+
: decode(bytes, compression, meta);
|
|
64
|
+
const { bytes, compression } = mask;
|
|
65
|
+
const decoded = await decoderFn(bytes, compression, metadata);
|
|
66
|
+
const data = decoded.layout === "pixel-interleaved" ? decoded.data : decoded.bands[0];
|
|
67
|
+
if (data instanceof Uint8Array) {
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
70
|
+
throw new Error("Expected mask data to decode to Uint8Array");
|
|
71
|
+
}
|
|
72
|
+
async function decodeTile(tile, metadata, pool) {
|
|
73
|
+
const decoderFn = (bytes, compression, meta) => pool
|
|
74
|
+
? pool.decode(bytes, compression, meta)
|
|
75
|
+
: decode(bytes, compression, meta);
|
|
76
|
+
if (Array.isArray(tile)) {
|
|
77
|
+
// Band-separate: each element is one band's compressed tile
|
|
78
|
+
const bandMetadata = { ...metadata, samplesPerPixel: 1 };
|
|
79
|
+
const decodedBands = await Promise.all(tile.map(({ bytes, compression }) => decoderFn(bytes, compression, bandMetadata)));
|
|
80
|
+
const bands = decodedBands.map((result) => result.layout === "band-separate" ? result.bands[0] : result.data);
|
|
81
|
+
return { layout: "band-separate", bands };
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// Pixel-interleaved: single compressed buffer covering all bands
|
|
85
|
+
// interleaved
|
|
86
|
+
const { bytes, compression } = tile;
|
|
87
|
+
return decoderFn(bytes, compression, metadata);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Fetch bytes from a COG, handling whether pixel/band interleaving. */
|
|
91
|
+
async function fetchCogBytes(self, x, y, { signal, } = {}) {
|
|
92
|
+
switch (self.cachedTags.planarConfiguration) {
|
|
93
|
+
case PlanarConfiguration.Contig: {
|
|
94
|
+
const tile = await getTile(self.image, x, y, self.dataSource, { signal });
|
|
95
|
+
if (tile === null) {
|
|
96
|
+
throw new Error(`Tile at (${x}, ${y}) not found`);
|
|
97
|
+
}
|
|
98
|
+
return tile;
|
|
99
|
+
}
|
|
100
|
+
case PlanarConfiguration.Separate:
|
|
101
|
+
return await fetchBandSeparateTileBytes(self, x, y, { signal });
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`Unsupported PlanarConfiguration: ${self.cachedTags.planarConfiguration}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function findBandSeparateTileByteRanges(self, x, y) {
|
|
107
|
+
// TODO: error here if user-provided band-indexes are out of bounds
|
|
108
|
+
const { x: tilesPerRow, y: tilesPerColumn } = self.image.tileCount;
|
|
109
|
+
const tilesPerBand = tilesPerRow * tilesPerColumn;
|
|
110
|
+
const numBands = self.cachedTags.samplesPerPixel;
|
|
111
|
+
const tileSizes = [...Array(numBands).keys()].map((band) => {
|
|
112
|
+
const bandIdx = band * tilesPerBand + y * tilesPerRow + x;
|
|
113
|
+
return self.image.getTileSize(bandIdx);
|
|
114
|
+
});
|
|
115
|
+
return Promise.all(tileSizes);
|
|
116
|
+
}
|
|
117
|
+
async function fetchBandSeparateTileBytes(self, x, y, { signal, } = {}) {
|
|
118
|
+
const byteRanges = await findBandSeparateTileByteRanges(self, x, y);
|
|
119
|
+
const buffers = byteRanges.map(async ({ offset, imageSize }) => {
|
|
120
|
+
const tile = await getBytes(self.image, offset, imageSize, self.dataSource, { signal });
|
|
121
|
+
if (tile === null) {
|
|
122
|
+
throw new Error(`Tile at (${x}, ${y}) not found`);
|
|
123
|
+
}
|
|
124
|
+
return tile;
|
|
125
|
+
});
|
|
126
|
+
return Promise.all(buffers);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Load a tile into a ArrayBuffer
|
|
130
|
+
*
|
|
131
|
+
* if the tile compression is JPEG, This will also apply the JPEG compression tables to the resulting ArrayBuffer see {@link getJpegHeader}
|
|
132
|
+
*
|
|
133
|
+
* Though this function lives upstream in @cogeotiff/core, we vendor it here so
|
|
134
|
+
* that we can use a custom fetch.
|
|
135
|
+
*
|
|
136
|
+
* This is to separate the source used for fetching header/IFD data (which is
|
|
137
|
+
* typically small and benefits from caching) from the source used for fetching
|
|
138
|
+
* tile data (which can be large and should avoid unnecessary copying through
|
|
139
|
+
* cache layers).
|
|
140
|
+
*/
|
|
141
|
+
async function getTile(image, x, y, source, options) {
|
|
142
|
+
const { size, tileSize: tiles } = image;
|
|
143
|
+
if (tiles == null)
|
|
144
|
+
throw new Error("Tiff is not tiled");
|
|
145
|
+
// TODO support GhostOptionTileOrder
|
|
146
|
+
const nyTiles = Math.ceil(size.height / tiles.height);
|
|
147
|
+
const nxTiles = Math.ceil(size.width / tiles.width);
|
|
148
|
+
if (x >= nxTiles || y >= nyTiles) {
|
|
149
|
+
throw new Error(`Tile index is outside of range x:${x} >= ${nxTiles} or y:${y} >= ${nyTiles}`);
|
|
150
|
+
}
|
|
151
|
+
const idx = y * nxTiles + x;
|
|
152
|
+
const totalTiles = nxTiles * nyTiles;
|
|
153
|
+
if (idx >= totalTiles)
|
|
154
|
+
throw new Error(`Tile index is outside of tile range: ${idx} >= ${totalTiles}`);
|
|
155
|
+
const { offset, imageSize } = await image.getTileSize(idx);
|
|
156
|
+
return getBytes(image, offset, imageSize, source, options);
|
|
157
|
+
}
|
|
158
|
+
/** Read image bytes at the given offset.
|
|
159
|
+
*
|
|
160
|
+
* Though this function lives upstream in @cogeotiff/core, we vendor it here so
|
|
161
|
+
* that we can use a custom fetch.
|
|
162
|
+
*
|
|
163
|
+
* This is to separate the source used for fetching header/IFD data (which is
|
|
164
|
+
* typically small and benefits from caching) from the source used for fetching
|
|
165
|
+
* tile data (which can be large and should avoid unnecessary copying through
|
|
166
|
+
* cache layers).
|
|
167
|
+
*/
|
|
168
|
+
async function getBytes(image, offset, byteCount, source, options) {
|
|
169
|
+
if (byteCount === 0)
|
|
170
|
+
return null;
|
|
171
|
+
const bytes = await source.fetch(offset, byteCount, options);
|
|
172
|
+
if (bytes.byteLength < byteCount) {
|
|
173
|
+
throw new Error(`Failed to fetch bytes from offset:${offset} wanted:${byteCount} got:${bytes.byteLength}`);
|
|
174
|
+
}
|
|
175
|
+
const compression = image.value(TiffTag.Compression) ?? Compression.None;
|
|
176
|
+
if (compression === Compression.Jpeg) {
|
|
177
|
+
return {
|
|
178
|
+
bytes: image.getJpegHeader(bytes),
|
|
179
|
+
compression,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return { bytes, compression };
|
|
183
|
+
}
|
|
44
184
|
/**
|
|
45
185
|
* Clip a decoded tile array to the valid image bounds.
|
|
46
186
|
*
|
|
@@ -59,41 +199,45 @@ function clipToImageBounds(self, x, y, array) {
|
|
|
59
199
|
if (clippedWidth === self.tileWidth && clippedHeight === self.tileHeight) {
|
|
60
200
|
return array;
|
|
61
201
|
}
|
|
202
|
+
const clippedMask = array.mask
|
|
203
|
+
? clipRows(array.mask, self.tileWidth, clippedWidth, clippedHeight, 1)
|
|
204
|
+
: array.mask;
|
|
62
205
|
if (array.layout === "pixel-interleaved") {
|
|
63
206
|
const { count, data } = array;
|
|
64
|
-
const
|
|
65
|
-
const clipped = new Ctor(clippedWidth * clippedHeight * count);
|
|
66
|
-
for (let r = 0; r < clippedHeight; r++) {
|
|
67
|
-
const srcOffset = r * self.tileWidth * count;
|
|
68
|
-
const dstOffset = r * clippedWidth * count;
|
|
69
|
-
clipped.set(data.subarray(srcOffset, srcOffset + clippedWidth * count), dstOffset);
|
|
70
|
-
}
|
|
207
|
+
const clipped = clipRows(data, self.tileWidth, clippedWidth, clippedHeight, count);
|
|
71
208
|
return {
|
|
72
209
|
...array,
|
|
73
210
|
width: clippedWidth,
|
|
74
211
|
height: clippedHeight,
|
|
75
212
|
data: clipped,
|
|
213
|
+
mask: clippedMask,
|
|
76
214
|
};
|
|
77
215
|
}
|
|
78
216
|
// band-separate
|
|
79
217
|
const { bands } = array;
|
|
80
|
-
const
|
|
81
|
-
const clippedBands = bands.map((band) => {
|
|
82
|
-
const clipped = new Ctor(clippedWidth * clippedHeight);
|
|
83
|
-
for (let r = 0; r < clippedHeight; r++) {
|
|
84
|
-
const srcOffset = r * self.tileWidth;
|
|
85
|
-
const dstOffset = r * clippedWidth;
|
|
86
|
-
clipped.set(band.subarray(srcOffset, srcOffset + clippedWidth), dstOffset);
|
|
87
|
-
}
|
|
88
|
-
return clipped;
|
|
89
|
-
});
|
|
218
|
+
const clippedBands = bands.map((band) => clipRows(band, self.tileWidth, clippedWidth, clippedHeight, 1));
|
|
90
219
|
return {
|
|
91
220
|
...array,
|
|
92
221
|
width: clippedWidth,
|
|
93
222
|
height: clippedHeight,
|
|
94
223
|
bands: clippedBands,
|
|
224
|
+
mask: clippedMask,
|
|
95
225
|
};
|
|
96
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Copy rows from a strided typed array, keeping only `clippedWidth * samplesPerPixel`
|
|
229
|
+
* values per row out of `tileWidth * samplesPerPixel`.
|
|
230
|
+
*/
|
|
231
|
+
function clipRows(src, tileWidth, clippedWidth, clippedHeight, samplesPerPixel) {
|
|
232
|
+
const srcStride = tileWidth * samplesPerPixel;
|
|
233
|
+
const dstStride = clippedWidth * samplesPerPixel;
|
|
234
|
+
// @ts-expect-error — typed array constructors are not in a common interface
|
|
235
|
+
const dst = new src.constructor(dstStride * clippedHeight);
|
|
236
|
+
for (let r = 0; r < clippedHeight; r++) {
|
|
237
|
+
dst.set(src.subarray(r * srcStride, r * srcStride + dstStride), r * dstStride);
|
|
238
|
+
}
|
|
239
|
+
return dst;
|
|
240
|
+
}
|
|
97
241
|
function getUniqueSampleFormat(sampleFormats, bitsPerSamples) {
|
|
98
242
|
const uniqueSampleFormats = new Set(sampleFormats);
|
|
99
243
|
const uniqueBitsPerSample = new Set(bitsPerSamples);
|
package/dist/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAI/D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgCrC,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAsB,EACtB,CAAS,EACT,CAAS,EACT,EACE,SAAS,GAAG,IAAI,EA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AAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type BandStatistics = {
|
|
2
|
+
max: number | null;
|
|
3
|
+
min: number | null;
|
|
4
|
+
mean: number | null;
|
|
5
|
+
std: number | null;
|
|
6
|
+
validPercent: number | null;
|
|
7
|
+
};
|
|
8
|
+
export type GDALMetadata = {
|
|
9
|
+
/** Mapping of 1-based band index to statistics. */
|
|
10
|
+
bandStatistics: Map<number, BandStatistics>;
|
|
11
|
+
offsets: number[];
|
|
12
|
+
scales: number[];
|
|
13
|
+
};
|
|
14
|
+
export declare function parseGDALMetadata(gdalMetadata: string | null | undefined, { count }: {
|
|
15
|
+
count: number;
|
|
16
|
+
}): GDALMetadata | null;
|
|
17
|
+
//# sourceMappingURL=gdal-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdal-metadata.d.ts","sourceRoot":"","sources":["../src/gdal-metadata.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,mDAAmD;IACnD,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACvC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAC3B,YAAY,GAAG,IAAI,CAgErB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function parseGDALMetadata(gdalMetadata, { count }) {
|
|
2
|
+
if (gdalMetadata == null)
|
|
3
|
+
return null;
|
|
4
|
+
const parser = new DOMParser();
|
|
5
|
+
const doc = parser.parseFromString(gdalMetadata, "text/xml");
|
|
6
|
+
const root = doc.documentElement;
|
|
7
|
+
if (root.tagName !== "GDALMetadata") {
|
|
8
|
+
throw new Error("Not a GDALMetadata XML block");
|
|
9
|
+
}
|
|
10
|
+
const bandStatistics = new Map();
|
|
11
|
+
const offsets = Array(count).fill(0);
|
|
12
|
+
const scales = Array(count).fill(1);
|
|
13
|
+
const getOrCreateBand = (sample) => {
|
|
14
|
+
const idx = parseInt(sample, 10) + 1; // 1-based
|
|
15
|
+
if (!bandStatistics.has(idx)) {
|
|
16
|
+
bandStatistics.set(idx, {
|
|
17
|
+
max: null,
|
|
18
|
+
min: null,
|
|
19
|
+
mean: null,
|
|
20
|
+
std: null,
|
|
21
|
+
validPercent: null,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return bandStatistics.get(idx);
|
|
25
|
+
};
|
|
26
|
+
for (const elem of Array.from(root.querySelectorAll("Item"))) {
|
|
27
|
+
const name = elem.getAttribute("name");
|
|
28
|
+
const sample = elem.getAttribute("sample");
|
|
29
|
+
const text = elem.textContent ?? "";
|
|
30
|
+
if (sample === null) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
switch (name) {
|
|
34
|
+
case "STATISTICS_MAXIMUM":
|
|
35
|
+
getOrCreateBand(sample).max = parseFloat(text);
|
|
36
|
+
break;
|
|
37
|
+
case "STATISTICS_MEAN":
|
|
38
|
+
getOrCreateBand(sample).mean = parseFloat(text);
|
|
39
|
+
break;
|
|
40
|
+
case "STATISTICS_MINIMUM":
|
|
41
|
+
getOrCreateBand(sample).min = parseFloat(text);
|
|
42
|
+
break;
|
|
43
|
+
case "STATISTICS_STDDEV":
|
|
44
|
+
getOrCreateBand(sample).std = parseFloat(text);
|
|
45
|
+
break;
|
|
46
|
+
case "STATISTICS_VALID_PERCENT":
|
|
47
|
+
getOrCreateBand(sample).validPercent = parseFloat(text);
|
|
48
|
+
break;
|
|
49
|
+
case "OFFSET":
|
|
50
|
+
offsets[parseInt(sample, 10)] = parseFloat(text);
|
|
51
|
+
break;
|
|
52
|
+
case "SCALE":
|
|
53
|
+
scales[parseInt(sample, 10)] = parseFloat(text);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { bandStatistics, offsets, scales };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=gdal-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gdal-metadata.js","sourceRoot":"","sources":["../src/gdal-metadata.ts"],"names":[],"mappings":"AAeA,MAAM,UAAU,iBAAiB,CAC/B,YAAuC,EACvC,EAAE,KAAK,EAAqB;IAE5B,IAAI,YAAY,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAEtC,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,GAAG,CAAC,eAAe,CAAC;IAEjC,IAAI,IAAI,CAAC,OAAO,KAAK,cAAc,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,cAAc,GAAG,IAAI,GAAG,EAA0B,CAAC;IACzD,MAAM,OAAO,GAAG,KAAK,CAAS,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,KAAK,CAAS,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE5C,MAAM,eAAe,GAAG,CAAC,MAAc,EAAkB,EAAE;QACzD,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,EAAE,EA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AK,0BAA0B;gBAC7B,eAAe,CAAC,MAAM,CAAC,CAAC,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;gBACxD,MAAM;YACR,KAAK,QAAQ;gBACX,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,OAAO;gBACV,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;gBAChD,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7C,CAAC"}
|
package/dist/geotiff.d.ts
CHANGED
|
@@ -1,30 +1,46 @@
|
|
|
1
|
-
import type { Source, TiffImage } from "@cogeotiff/core";
|
|
1
|
+
import type { Source, TiffImage, TiffImageTileCount } from "@cogeotiff/core";
|
|
2
2
|
import { Tiff } from "@cogeotiff/core";
|
|
3
3
|
import type { Affine } from "@developmentseed/affine";
|
|
4
4
|
import type { ProjJson } from "./crs.js";
|
|
5
|
+
import type { BandStatistics, GDALMetadata } from "./gdal-metadata.js";
|
|
5
6
|
import type { CachedTags, GeoKeyDirectory } from "./ifd.js";
|
|
6
7
|
import { Overview } from "./overview.js";
|
|
8
|
+
import type { DecoderPool } from "./pool/pool.js";
|
|
7
9
|
import type { Tile } from "./tile.js";
|
|
8
10
|
/**
|
|
9
|
-
* A
|
|
11
|
+
* A high-level GeoTIFF abstraction built on
|
|
12
|
+
* {@link https://github.com/blacha/cogeotiff | @cogeotiff/core}'s `Tiff` and
|
|
13
|
+
* `TiffImage` classes.
|
|
10
14
|
*
|
|
11
|
-
*
|
|
12
|
-
* and exposes sorted overviews.
|
|
15
|
+
* This class separates data IFDs from mask IFDs, pairs them by resolution
|
|
16
|
+
* level, and exposes sorted overviews. Intentionally mirrors the Python
|
|
17
|
+
* {@link https://github.com/developmentseed/async-geotiff | async-geotiff} API
|
|
18
|
+
* as closely as possible.
|
|
13
19
|
*
|
|
14
|
-
* Construct via
|
|
20
|
+
* Construct via {@link GeoTIFF.fromUrl}, {@link GeoTIFF.fromArrayBuffer},
|
|
21
|
+
* {@link GeoTIFF.open} or {@link GeoTIFF.fromTiff}.
|
|
22
|
+
*
|
|
23
|
+
* @see {@link Overview} for reduced-resolution overview images.
|
|
15
24
|
*/
|
|
16
25
|
export declare class GeoTIFF {
|
|
17
26
|
/**
|
|
18
27
|
* Reduced-resolution overview levels, sorted finest-to-coarsest.
|
|
19
28
|
*
|
|
20
|
-
* Does not include the full-resolution image — use
|
|
21
|
-
*
|
|
29
|
+
* Does not include the full-resolution image — use {@link fetchTile} on the
|
|
30
|
+
* GeoTIFF instance itself for that.
|
|
22
31
|
*/
|
|
23
32
|
readonly overviews: Overview[];
|
|
24
33
|
/** A cached CRS value. */
|
|
25
34
|
private _crs?;
|
|
26
35
|
/** Cached TIFF tags that are pre-fetched when opening the GeoTIFF. */
|
|
27
36
|
readonly cachedTags: CachedTags;
|
|
37
|
+
/** The data source used for fetching tile data.
|
|
38
|
+
*
|
|
39
|
+
* This is typically the raw source (e.g. HTTP or memory) rather than a
|
|
40
|
+
* layered source with caching and chunking, to avoid unnecessary copying of
|
|
41
|
+
* tile data through cache layers.
|
|
42
|
+
*/
|
|
43
|
+
readonly dataSource: Pick<Source, "fetch">;
|
|
28
44
|
/** The underlying Tiff instance. */
|
|
29
45
|
readonly tiff: Tiff;
|
|
30
46
|
/** The primary (full-resolution) TiffImage. */
|
|
@@ -33,21 +49,53 @@ export declare class GeoTIFF {
|
|
|
33
49
|
readonly maskImage: TiffImage | null;
|
|
34
50
|
/** The GeoKeyDirectory of the primary IFD. */
|
|
35
51
|
readonly gkd: GeoKeyDirectory;
|
|
52
|
+
/** Parsed GDALMetadata tag, if present. */
|
|
53
|
+
readonly gdalMetadata: GDALMetadata | null;
|
|
36
54
|
private constructor();
|
|
37
55
|
/**
|
|
38
56
|
* Open a GeoTIFF from a @cogeotiff/core Source.
|
|
39
57
|
*
|
|
40
58
|
* This creates and initialises the underlying Tiff, then classifies IFDs.
|
|
59
|
+
*
|
|
60
|
+
* @param options.dataSource A source for fetching tile data. This is separate from the source used to construct the TIFF to allow for separate caching implementations.
|
|
61
|
+
* @param options.headerSource 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.
|
|
62
|
+
* @param options.prefetch 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.
|
|
41
63
|
*/
|
|
42
|
-
static open(
|
|
64
|
+
static open(options: {
|
|
65
|
+
dataSource: Pick<Source, "fetch">;
|
|
66
|
+
headerSource: Source;
|
|
67
|
+
prefetch?: number;
|
|
68
|
+
}): Promise<GeoTIFF>;
|
|
43
69
|
/**
|
|
44
70
|
* Create a GeoTIFF from an already-initialised Tiff instance.
|
|
45
71
|
*
|
|
46
72
|
* All IFDs are walked; mask IFDs are matched to data IFDs by matching
|
|
47
73
|
* (width, height). Overviews are sorted from finest to coarsest resolution.
|
|
74
|
+
*
|
|
75
|
+
* @param dataSource A source for fetching tile data. This is separate from the source used to construct the TIFF to allow for separate caching implementations.
|
|
76
|
+
*/
|
|
77
|
+
static fromTiff(tiff: Tiff, dataSource: Pick<Source, "fetch">): Promise<GeoTIFF>;
|
|
78
|
+
/**
|
|
79
|
+
* Create a GeoTIFF from an ArrayBuffer containing the entire file.
|
|
80
|
+
*
|
|
81
|
+
* This is a convenience method that wraps the ArrayBuffer in a memory source
|
|
82
|
+
* and calls {@link GeoTIFF.open}. For large files, consider using
|
|
83
|
+
* {@link GeoTIFF.fromUrl} or {@link GeoTIFF.open} with a chunked HTTP source
|
|
84
|
+
* to avoid loading the entire file into memory at once.
|
|
85
|
+
*
|
|
86
|
+
* @param input The ArrayBuffer containing the GeoTIFF file data.
|
|
87
|
+
* @returns A Promise that resolves to a GeoTIFF instance.
|
|
48
88
|
*/
|
|
49
|
-
static fromTiff(tiff: Tiff): Promise<GeoTIFF>;
|
|
50
89
|
static fromArrayBuffer(input: ArrayBuffer): Promise<GeoTIFF>;
|
|
90
|
+
/**
|
|
91
|
+
* Create a new GeoTIFF from a URL.
|
|
92
|
+
*
|
|
93
|
+
* @param url The URL of the GeoTIFF to open.
|
|
94
|
+
* @param options Optional parameters for chunk size and cache size.
|
|
95
|
+
* @param options.chunkSize The minimum size for each request made to the source while reading header metadata. Defaults to 32KB.
|
|
96
|
+
* @param options.cacheSize The size of the cache for recently accessed header chunks. Currently no caching is applied to data fetches. Defaults to 1MB.
|
|
97
|
+
* @returns A Promise that resolves to a GeoTIFF instance.
|
|
98
|
+
*/
|
|
51
99
|
static fromUrl(url: string | URL, { chunkSize, cacheSize, }?: {
|
|
52
100
|
chunkSize?: number;
|
|
53
101
|
cacheSize?: number;
|
|
@@ -65,14 +113,37 @@ export declare class GeoTIFF {
|
|
|
65
113
|
get width(): number;
|
|
66
114
|
/** Image height in pixels. */
|
|
67
115
|
get height(): number;
|
|
116
|
+
/** The number of tiles in the x and y directions */
|
|
117
|
+
get tileCount(): TiffImageTileCount;
|
|
68
118
|
/** Tile width in pixels. */
|
|
69
119
|
get tileWidth(): number;
|
|
70
120
|
/** Tile height in pixels. */
|
|
71
121
|
get tileHeight(): number;
|
|
72
|
-
/** The
|
|
122
|
+
/** The no data value, or null if not set. */
|
|
73
123
|
get nodata(): number | null;
|
|
74
124
|
/** Whether the primary image is tiled. */
|
|
75
125
|
get isTiled(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* The pre-existing statistics for each band, if available.
|
|
128
|
+
*
|
|
129
|
+
* Extracted from the GDALMetadata TIFF tag; never computed on demand.
|
|
130
|
+
* Keys are **1-based** band indices to match GDAL's convention.
|
|
131
|
+
*
|
|
132
|
+
* Returns `null` if no statistics are stored in the file.
|
|
133
|
+
*/
|
|
134
|
+
get storedStats(): ReadonlyMap<number, BandStatistics> | null;
|
|
135
|
+
/**
|
|
136
|
+
* The offset for each band (0-indexed), defaulting to 0.
|
|
137
|
+
*
|
|
138
|
+
* Extracted from the GDALMetadata TIFF tag.
|
|
139
|
+
*/
|
|
140
|
+
get offsets(): number[];
|
|
141
|
+
/**
|
|
142
|
+
* The scale for each band (0-indexed), defaulting to 1.
|
|
143
|
+
*
|
|
144
|
+
* Extracted from the GDALMetadata TIFF tag.
|
|
145
|
+
*/
|
|
146
|
+
get scales(): number[];
|
|
76
147
|
/** Number of bands (samples per pixel). */
|
|
77
148
|
get count(): number;
|
|
78
149
|
/** Bounding box [minX, minY, maxX, maxY] in the CRS. */
|
|
@@ -81,9 +152,18 @@ export declare class GeoTIFF {
|
|
|
81
152
|
* Return the dataset's georeferencing transformation matrix.
|
|
82
153
|
*/
|
|
83
154
|
get transform(): Affine;
|
|
84
|
-
/** Fetch a single tile from the full-resolution image.
|
|
155
|
+
/** Fetch a single tile from the full-resolution image.
|
|
156
|
+
*
|
|
157
|
+
* @param x The tile column index (0-based).
|
|
158
|
+
* @param y The tile row index (0-based).
|
|
159
|
+
* @param options Optional parameters for fetching the tile.
|
|
160
|
+
* @param options.boundless Whether to clip tiles that are partially outside the image bounds. When `true`, no clipping is applied. Defaults to `true`.
|
|
161
|
+
* @param options.pool An optional {@link DecoderPool} for decoding the tile data. If not provided, a new decoder will be created for each tile.
|
|
162
|
+
* @param options.signal An optional {@link AbortSignal} to cancel the fetch request.
|
|
163
|
+
*/
|
|
85
164
|
fetchTile(x: number, y: number, options?: {
|
|
86
165
|
boundless?: boolean;
|
|
166
|
+
pool?: DecoderPool;
|
|
87
167
|
signal?: AbortSignal;
|
|
88
168
|
}): Promise<Tile>;
|
|
89
169
|
/**
|
package/dist/geotiff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geotiff.d.ts","sourceRoot":"","sources":["../src/geotiff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geotiff.d.ts","sourceRoot":"","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