Skip to content

Commit 849111a

Browse files
Merge pull request #296 from MichaelBuhler/fix-read-rasters-return-type
TypeScript: add `height` and `width` to return type of `readRasters()`
2 parents 068085b + 22ac9e4 commit 849111a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/geotiff.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export { setLogger };
2727
* TypedArray
2828
*/
2929

30+
/**
31+
* @typedef { (TypedArray | TypedArray[]) & { height: number; width: number } } ReadRasterResult
32+
*/
33+
3034
function getFieldTypeLength(fieldType) {
3135
switch (fieldType) {
3236
case fieldTypes.BYTE: case fieldTypes.ASCII: case fieldTypes.SBYTE: case fieldTypes.UNDEFINED:
@@ -182,7 +186,7 @@ class GeoTIFFBase {
182186
* image is called and the result returned.
183187
* @see GeoTIFFImage.readRasters
184188
* @param {import('./geotiffimage').ReadRasterOptions} [options={}] optional parameters
185-
* @returns {Promise<(TypedArray|TypedArray[])>} the decoded arrays as a promise
189+
* @returns {Promise<ReadRasterResult>} the decoded arrays as a promise
186190
*/
187191
async readRasters(options = {}) {
188192
const { window: imageWindow, width, height } = options;

src/geotiffimage.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { resample, resampleInterleaved } from './resample.js';
3232
*/
3333

3434
/** @typedef {import("./geotiff.js").TypedArray} TypedArray */
35+
/** @typedef {import("./geotiff.js").ReadRasterResult} ReadRasterResult */
3536

3637
function sum(array, start, end) {
3738
let s = 0;
@@ -422,15 +423,15 @@ class GeoTIFFImage {
422423
* @private
423424
* @param {Array} imageWindow The image window in pixel coordinates
424425
* @param {Array} samples The selected samples (0-based indices)
425-
* @param {TypedArray[]|TypedArray} valueArrays The array(s) to write into
426+
* @param {TypedArray|TypedArray[]} valueArrays The array(s) to write into
426427
* @param {Boolean} interleave Whether or not to write in an interleaved manner
427428
* @param {import("./geotiff").Pool|AbstractDecoder} poolOrDecoder the decoder or decoder pool
428429
* @param {number} width the width of window to be read into
429430
* @param {number} height the height of window to be read into
430431
* @param {number} resampleMethod the resampling method to be used when interpolating
431432
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
432433
* to be aborted
433-
* @returns {Promise<TypedArray[]>|Promise<TypedArray>}
434+
* @returns {Promise<ReadRasterResult>}
434435
*/
435436
async _readRaster(imageWindow, samples, valueArrays, interleave, poolOrDecoder, width,
436437
height, resampleMethod, signal) {
@@ -554,7 +555,7 @@ class GeoTIFFImage {
554555
* of the raster is read for each sample.
555556
*
556557
* @param {ReadRasterOptions} [options={}] optional parameters
557-
* @returns {Promise.<(TypedArray|TypedArray[])>} the decoded arrays as a promise
558+
* @returns {Promise<ReadRasterResult>} the decoded arrays as a promise
558559
*/
559560
async readRasters({
560561
window: wnd, samples = [], interleave, pool = null,
@@ -635,7 +636,7 @@ class GeoTIFFImage {
635636
* @param {boolean} [options.enableAlpha=false] Enable reading alpha channel if present.
636637
* @param {AbortSignal} [options.signal] An AbortSignal that may be signalled if the request is
637638
* to be aborted
638-
* @returns {Promise<TypedArray|TypedArray[]>} the RGB array as a Promise
639+
* @returns {Promise<ReadRasterResult>} the RGB array as a Promise
639640
*/
640641
async readRGB({ window, interleave = true, pool = null, width, height,
641642
resampleMethod, enableAlpha = false, signal } = {}) {

0 commit comments

Comments
 (0)