ol 7.0.1-dev.1661646168074 → 7.0.1-dev.1661693437008
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/package.json +1 -1
- package/source/GeoTIFF.d.ts +20 -1
- package/source/GeoTIFF.d.ts.map +1 -1
- package/source/GeoTIFF.js +171 -91
- package/util.js +1 -1
package/package.json
CHANGED
package/source/GeoTIFF.d.ts
CHANGED
|
@@ -233,6 +233,11 @@ declare class GeoTIFFSource extends DataTile {
|
|
|
233
233
|
* @private
|
|
234
234
|
*/
|
|
235
235
|
private sourceImagery_;
|
|
236
|
+
/**
|
|
237
|
+
* @type {Array<Array<GeoTIFFImage>>}
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
private sourceMasks_;
|
|
236
241
|
/**
|
|
237
242
|
* @type {Array<number>}
|
|
238
243
|
* @private
|
|
@@ -293,7 +298,21 @@ declare class GeoTIFFSource extends DataTile {
|
|
|
293
298
|
* @private
|
|
294
299
|
*/
|
|
295
300
|
private configure_;
|
|
296
|
-
|
|
301
|
+
/**
|
|
302
|
+
* @param {number} z The z tile index.
|
|
303
|
+
* @param {number} x The x tile index.
|
|
304
|
+
* @param {number} y The y tile index.
|
|
305
|
+
* @return {Promise} The composed tile data.
|
|
306
|
+
* @private
|
|
307
|
+
*/
|
|
308
|
+
private loadTile_;
|
|
309
|
+
/**
|
|
310
|
+
* @param {import("../size.js").Size} sourceTileSize The source tile size.
|
|
311
|
+
* @param {Array} sourceSamples The source samples.
|
|
312
|
+
* @return {import("../DataTile.js").Data} The composed tile data.
|
|
313
|
+
* @private
|
|
314
|
+
*/
|
|
315
|
+
private composeTile_;
|
|
297
316
|
}
|
|
298
317
|
import DataTile from "./DataTile.js";
|
|
299
318
|
//# sourceMappingURL=GeoTIFF.d.ts.map
|
package/source/GeoTIFF.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeoTIFF.d.ts","sourceR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4GC;CACF"}
|
package/source/GeoTIFF.js
CHANGED
|
@@ -19,6 +19,18 @@ import {clamp} from '../math.js';
|
|
|
19
19
|
import {getCenter, getIntersection} from '../extent.js';
|
|
20
20
|
import {fromCode as unitsFromCode} from '../proj/Units.js';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Determine if an image type is a mask.
|
|
24
|
+
* See https://www.awaresystems.be/imaging/tiff/tifftags/newsubfiletype.html
|
|
25
|
+
* @param {GeoTIFFImage} image The image.
|
|
26
|
+
* @return {boolean} The image is a mask.
|
|
27
|
+
*/
|
|
28
|
+
function isMask(image) {
|
|
29
|
+
const fileDirectory = image.fileDirectory;
|
|
30
|
+
const type = fileDirectory.NewSubfileType || 0;
|
|
31
|
+
return (type & 4) === 4;
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
/**
|
|
23
35
|
* @typedef {Object} SourceInfo
|
|
24
36
|
* @property {string} [url] URL for the source GeoTIFF.
|
|
@@ -363,6 +375,12 @@ class GeoTIFFSource extends DataTile {
|
|
|
363
375
|
*/
|
|
364
376
|
this.sourceImagery_ = new Array(numSources);
|
|
365
377
|
|
|
378
|
+
/**
|
|
379
|
+
* @type {Array<Array<GeoTIFFImage>>}
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
this.sourceMasks_ = new Array(numSources);
|
|
383
|
+
|
|
366
384
|
/**
|
|
367
385
|
* @type {Array<number>}
|
|
368
386
|
* @private
|
|
@@ -467,8 +485,22 @@ class GeoTIFFSource extends DataTile {
|
|
|
467
485
|
|
|
468
486
|
const sourceCount = sources.length;
|
|
469
487
|
for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
|
|
470
|
-
const images =
|
|
488
|
+
const images = [];
|
|
489
|
+
const masks = [];
|
|
490
|
+
sources[sourceIndex].forEach((item) => {
|
|
491
|
+
if (isMask(item)) {
|
|
492
|
+
masks.push(item);
|
|
493
|
+
} else {
|
|
494
|
+
images.push(item);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
|
|
471
498
|
const imageCount = images.length;
|
|
499
|
+
if (masks.length > 0 && masks.length !== imageCount) {
|
|
500
|
+
throw new Error(
|
|
501
|
+
`Expected one mask per image found ${masks.length} masks and ${imageCount} images`
|
|
502
|
+
);
|
|
503
|
+
}
|
|
472
504
|
|
|
473
505
|
let sourceExtent;
|
|
474
506
|
let sourceOrigin;
|
|
@@ -574,6 +606,7 @@ class GeoTIFFSource extends DataTile {
|
|
|
574
606
|
}
|
|
575
607
|
|
|
576
608
|
this.sourceImagery_[sourceIndex] = images.reverse();
|
|
609
|
+
this.sourceMasks_[sourceIndex] = masks.reverse();
|
|
577
610
|
}
|
|
578
611
|
|
|
579
612
|
for (let i = 0, ii = this.sourceImagery_.length; i < ii; ++i) {
|
|
@@ -606,6 +639,10 @@ class GeoTIFFSource extends DataTile {
|
|
|
606
639
|
this.addAlpha_ = true;
|
|
607
640
|
break;
|
|
608
641
|
}
|
|
642
|
+
if (this.sourceMasks_[sourceIndex].length) {
|
|
643
|
+
this.addAlpha_ = true;
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
609
646
|
|
|
610
647
|
const values = nodataValues[sourceIndex];
|
|
611
648
|
|
|
@@ -659,15 +696,20 @@ class GeoTIFFSource extends DataTile {
|
|
|
659
696
|
});
|
|
660
697
|
}
|
|
661
698
|
|
|
699
|
+
/**
|
|
700
|
+
* @param {number} z The z tile index.
|
|
701
|
+
* @param {number} x The x tile index.
|
|
702
|
+
* @param {number} y The y tile index.
|
|
703
|
+
* @return {Promise} The composed tile data.
|
|
704
|
+
* @private
|
|
705
|
+
*/
|
|
662
706
|
loadTile_(z, x, y) {
|
|
663
707
|
const sourceTileSize = this.getTileSize(z);
|
|
664
708
|
const sourceCount = this.sourceImagery_.length;
|
|
665
|
-
const requests = new Array(sourceCount);
|
|
666
|
-
const addAlpha = this.addAlpha_;
|
|
667
|
-
const bandCount = this.bandCount;
|
|
668
|
-
const samplesPerPixel = this.samplesPerPixel_;
|
|
709
|
+
const requests = new Array(sourceCount * 2);
|
|
669
710
|
const nodataValues = this.nodataValues_;
|
|
670
711
|
const sourceInfo = this.sourceInfo_;
|
|
712
|
+
const pool = getWorkerPool();
|
|
671
713
|
for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
|
|
672
714
|
const source = sourceInfo[sourceIndex];
|
|
673
715
|
const resolutionFactor = this.resolutionFactors_[sourceIndex];
|
|
@@ -705,112 +747,150 @@ class GeoTIFFSource extends DataTile {
|
|
|
705
747
|
height: sourceTileSize[1],
|
|
706
748
|
samples: samples,
|
|
707
749
|
fillValue: fillValue,
|
|
708
|
-
pool:
|
|
750
|
+
pool: pool,
|
|
751
|
+
interleave: false,
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
// requests after `sourceCount` are for mask data (if any)
|
|
755
|
+
const maskIndex = sourceCount + sourceIndex;
|
|
756
|
+
const mask = this.sourceMasks_[sourceIndex][z];
|
|
757
|
+
if (!mask) {
|
|
758
|
+
requests[maskIndex] = Promise.resolve(null);
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
requests[maskIndex] = mask.readRasters({
|
|
763
|
+
window: pixelBounds,
|
|
764
|
+
width: sourceTileSize[0],
|
|
765
|
+
height: sourceTileSize[1],
|
|
766
|
+
samples: [0],
|
|
767
|
+
pool: pool,
|
|
709
768
|
interleave: false,
|
|
710
769
|
});
|
|
711
770
|
}
|
|
712
771
|
|
|
772
|
+
return Promise.all(requests)
|
|
773
|
+
.then(this.composeTile_.bind(this, sourceTileSize))
|
|
774
|
+
.catch(function (error) {
|
|
775
|
+
console.error(error); // eslint-disable-line no-console
|
|
776
|
+
throw error;
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* @param {import("../size.js").Size} sourceTileSize The source tile size.
|
|
782
|
+
* @param {Array} sourceSamples The source samples.
|
|
783
|
+
* @return {import("../DataTile.js").Data} The composed tile data.
|
|
784
|
+
* @private
|
|
785
|
+
*/
|
|
786
|
+
composeTile_(sourceTileSize, sourceSamples) {
|
|
787
|
+
const metadata = this.metadata_;
|
|
788
|
+
const sourceInfo = this.sourceInfo_;
|
|
789
|
+
const sourceCount = this.sourceImagery_.length;
|
|
790
|
+
const bandCount = this.bandCount;
|
|
791
|
+
const samplesPerPixel = this.samplesPerPixel_;
|
|
792
|
+
const nodataValues = this.nodataValues_;
|
|
793
|
+
const normalize = this.normalize_;
|
|
794
|
+
const addAlpha = this.addAlpha_;
|
|
795
|
+
|
|
713
796
|
const pixelCount = sourceTileSize[0] * sourceTileSize[1];
|
|
714
797
|
const dataLength = pixelCount * bandCount;
|
|
715
|
-
const normalize = this.normalize_;
|
|
716
|
-
const metadata = this.metadata_;
|
|
717
798
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
data = new Float32Array(dataLength);
|
|
726
|
-
}
|
|
799
|
+
/** @type {Uint8Array|Float32Array} */
|
|
800
|
+
let data;
|
|
801
|
+
if (normalize) {
|
|
802
|
+
data = new Uint8Array(dataLength);
|
|
803
|
+
} else {
|
|
804
|
+
data = new Float32Array(dataLength);
|
|
805
|
+
}
|
|
727
806
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
let min = source.min;
|
|
735
|
-
let max = source.max;
|
|
736
|
-
let gain, bias;
|
|
737
|
-
if (normalize) {
|
|
738
|
-
const stats = metadata[sourceIndex][0];
|
|
739
|
-
if (min === undefined) {
|
|
740
|
-
if (stats && STATISTICS_MINIMUM in stats) {
|
|
741
|
-
min = parseFloat(stats[STATISTICS_MINIMUM]);
|
|
742
|
-
} else {
|
|
743
|
-
min = getMinForDataType(sourceSamples[sourceIndex][0]);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
if (max === undefined) {
|
|
747
|
-
if (stats && STATISTICS_MAXIMUM in stats) {
|
|
748
|
-
max = parseFloat(stats[STATISTICS_MAXIMUM]);
|
|
749
|
-
} else {
|
|
750
|
-
max = getMaxForDataType(sourceSamples[sourceIndex][0]);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
807
|
+
let dataIndex = 0;
|
|
808
|
+
for (let pixelIndex = 0; pixelIndex < pixelCount; ++pixelIndex) {
|
|
809
|
+
let transparent = addAlpha;
|
|
810
|
+
for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
|
|
811
|
+
const source = sourceInfo[sourceIndex];
|
|
753
812
|
|
|
754
|
-
|
|
755
|
-
|
|
813
|
+
let min = source.min;
|
|
814
|
+
let max = source.max;
|
|
815
|
+
let gain, bias;
|
|
816
|
+
if (normalize) {
|
|
817
|
+
const stats = metadata[sourceIndex][0];
|
|
818
|
+
if (min === undefined) {
|
|
819
|
+
if (stats && STATISTICS_MINIMUM in stats) {
|
|
820
|
+
min = parseFloat(stats[STATISTICS_MINIMUM]);
|
|
821
|
+
} else {
|
|
822
|
+
min = getMinForDataType(sourceSamples[sourceIndex][0]);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (max === undefined) {
|
|
826
|
+
if (stats && STATISTICS_MAXIMUM in stats) {
|
|
827
|
+
max = parseFloat(stats[STATISTICS_MAXIMUM]);
|
|
828
|
+
} else {
|
|
829
|
+
max = getMaxForDataType(sourceSamples[sourceIndex][0]);
|
|
756
830
|
}
|
|
831
|
+
}
|
|
757
832
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
++sampleIndex
|
|
762
|
-
) {
|
|
763
|
-
const sourceValue =
|
|
764
|
-
sourceSamples[sourceIndex][sampleIndex][pixelIndex];
|
|
833
|
+
gain = 255 / (max - min);
|
|
834
|
+
bias = -min * gain;
|
|
835
|
+
}
|
|
765
836
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
837
|
+
for (
|
|
838
|
+
let sampleIndex = 0;
|
|
839
|
+
sampleIndex < samplesPerPixel[sourceIndex];
|
|
840
|
+
++sampleIndex
|
|
841
|
+
) {
|
|
842
|
+
const sourceValue =
|
|
843
|
+
sourceSamples[sourceIndex][sampleIndex][pixelIndex];
|
|
844
|
+
|
|
845
|
+
let value;
|
|
846
|
+
if (normalize) {
|
|
847
|
+
value = clamp(gain * sourceValue + bias, 0, 255);
|
|
848
|
+
} else {
|
|
849
|
+
value = sourceValue;
|
|
850
|
+
}
|
|
772
851
|
|
|
773
|
-
|
|
774
|
-
|
|
852
|
+
if (!addAlpha) {
|
|
853
|
+
data[dataIndex] = value;
|
|
854
|
+
} else {
|
|
855
|
+
let nodata = source.nodata;
|
|
856
|
+
if (nodata === undefined) {
|
|
857
|
+
let bandIndex;
|
|
858
|
+
if (source.bands) {
|
|
859
|
+
bandIndex = source.bands[sampleIndex] - 1;
|
|
775
860
|
} else {
|
|
776
|
-
|
|
777
|
-
if (nodata === undefined) {
|
|
778
|
-
let bandIndex;
|
|
779
|
-
if (source.bands) {
|
|
780
|
-
bandIndex = source.bands[sampleIndex] - 1;
|
|
781
|
-
} else {
|
|
782
|
-
bandIndex = sampleIndex;
|
|
783
|
-
}
|
|
784
|
-
nodata = nodataValues[sourceIndex][bandIndex];
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
const nodataIsNaN = isNaN(nodata);
|
|
788
|
-
if (
|
|
789
|
-
(!nodataIsNaN && sourceValue !== nodata) ||
|
|
790
|
-
(nodataIsNaN && !isNaN(sourceValue))
|
|
791
|
-
) {
|
|
792
|
-
transparent = false;
|
|
793
|
-
data[dataIndex] = value;
|
|
794
|
-
}
|
|
861
|
+
bandIndex = sampleIndex;
|
|
795
862
|
}
|
|
796
|
-
|
|
863
|
+
nodata = nodataValues[sourceIndex][bandIndex];
|
|
797
864
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
if (
|
|
801
|
-
|
|
865
|
+
|
|
866
|
+
const nodataIsNaN = isNaN(nodata);
|
|
867
|
+
if (
|
|
868
|
+
(!nodataIsNaN && sourceValue !== nodata) ||
|
|
869
|
+
(nodataIsNaN && !isNaN(sourceValue))
|
|
870
|
+
) {
|
|
871
|
+
transparent = false;
|
|
872
|
+
data[dataIndex] = value;
|
|
802
873
|
}
|
|
803
|
-
dataIndex++;
|
|
804
874
|
}
|
|
875
|
+
dataIndex++;
|
|
805
876
|
}
|
|
877
|
+
if (!transparent) {
|
|
878
|
+
const maskIndex = sourceCount + sourceIndex;
|
|
879
|
+
const mask = sourceSamples[maskIndex];
|
|
880
|
+
if (mask && !mask[0][pixelIndex]) {
|
|
881
|
+
transparent = true;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (addAlpha) {
|
|
886
|
+
if (!transparent) {
|
|
887
|
+
data[dataIndex] = 255;
|
|
888
|
+
}
|
|
889
|
+
dataIndex++;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
806
892
|
|
|
807
|
-
|
|
808
|
-
})
|
|
809
|
-
.catch(function (error) {
|
|
810
|
-
// output then rethrow
|
|
811
|
-
console.error(error); // eslint-disable-line no-console
|
|
812
|
-
throw error;
|
|
813
|
-
});
|
|
893
|
+
return data;
|
|
814
894
|
}
|
|
815
895
|
}
|
|
816
896
|
|
package/util.js
CHANGED