Use band numbers starting with one

This commit is contained in:
Tim Schaub
2021-09-06 11:31:08 -06:00
parent 8a67c5dbe6
commit 0e4c40e315
2 changed files with 14 additions and 8 deletions
+2 -2
View File
@@ -7,14 +7,14 @@ const source = new GeoTIFF({
sources: [ sources: [
{ {
url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R10m.tif', url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R10m.tif',
bands: [2, 3], bands: [3, 4],
min: 0, min: 0,
nodata: 0, nodata: 0,
max: 65535, max: 65535,
}, },
{ {
url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R60m.tif', url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R60m.tif',
bands: [8], bands: [9],
min: 0, min: 0,
nodata: 0, nodata: 0,
max: 65535, max: 65535,
+12 -6
View File
@@ -20,9 +20,9 @@ import {toSize} from '../size.js';
* the configured min and max. * the configured min and max.
* @property {number} [nodata] Values to discard. When provided, an additional band (alpha) will be added * @property {number} [nodata] Values to discard. When provided, an additional band (alpha) will be added
* to the data. * to the data.
* @property {Array<number>} [bands] Indices of the bands to be read from. If not provided, all bands will * @property {Array<number>} [bands] Band numbers to be read from (where the first band is `1`). If not provided, all bands will
* be read. If, for example, a GeoTIFF has red, green, blue and near-infrared bands and you only need the * be read. For example, if a GeoTIFF has blue (1), green (2), red (3), and near-infrared (4) bands, and you only need the
* infrared band, configure `bands: [3]`. * near-infrared band, configure `bands: [4]`.
*/ */
let workerPool; let workerPool;
@@ -385,7 +385,7 @@ class GeoTIFFSource extends DataTile {
const bands = this.sourceInfo_[sourceIndex].bands; const bands = this.sourceInfo_[sourceIndex].bands;
if (bands) { if (bands) {
for (let i = 0; i < bands.length; ++i) { for (let i = 0; i < bands.length; ++i) {
if (!isNaN(values[bands[i]])) { if (!isNaN(values[bands[i] - 1])) {
this.addAlpha_ = true; this.addAlpha_ = true;
break outer; break outer;
} }
@@ -442,11 +442,17 @@ class GeoTIFFSource extends DataTile {
Math.round((y + 1) * (size[1] * resolutionFactor)), Math.round((y + 1) * (size[1] * resolutionFactor)),
]; ];
const image = this.sourceImagery_[sourceIndex][z]; const image = this.sourceImagery_[sourceIndex][z];
let samples;
if (source.bands) {
samples = source.bands.map(function (bandNumber) {
return bandNumber - 1;
});
}
requests[sourceIndex] = image.readRasters({ requests[sourceIndex] = image.readRasters({
window: pixelBounds, window: pixelBounds,
width: size[0], width: size[0],
height: size[1], height: size[1],
samples: source.bands, samples: samples,
fillValue: source.nodata, fillValue: source.nodata,
pool: getWorkerPool(), pool: getWorkerPool(),
}); });
@@ -491,7 +497,7 @@ class GeoTIFFSource extends DataTile {
if (nodata === undefined) { if (nodata === undefined) {
let bandIndex; let bandIndex;
if (source.bands) { if (source.bands) {
bandIndex = source.bands[sampleIndex]; bandIndex = source.bands[sampleIndex] - 1;
} else { } else {
bandIndex = sampleIndex; bandIndex = sampleIndex;
} }