-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-gdal-stats.js
32 lines (28 loc) · 1.21 KB
/
get-gdal-stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module.exports = function getGDALStats(image, bandIndex) {
if (typeof bandIndex !== "number") throw new Error("you must specify bandIndex");
const bandStats = {};
const gdalMetadata = image.getGDALMetadata(bandIndex);
if (gdalMetadata) {
if (["string", "number"].includes(typeof gdalMetadata.STATISTICS_MAXIMUM)) {
const max = Number(gdalMetadata.STATISTICS_MAXIMUM);
if (!isNaN(max)) bandStats.max = max;
}
if (["string", "number"].includes(typeof gdalMetadata.STATISTICS_MINIMUM)) {
const min = Number(gdalMetadata.STATISTICS_MINIMUM);
if (!isNaN(min)) bandStats.min = min;
}
if (["string", "number"].includes(typeof gdalMetadata.STATISTICS_MEAN)) {
const mean = Number(gdalMetadata.STATISTICS_MEAN);
if (!isNaN(mean)) bandStats.mean = mean;
}
if (["string", "number"].includes(typeof gdalMetadata.STATISTICS_MEAN)) {
const median = Number(gdalMetadata.STATISTICS_MEDIAN);
if (!isNaN(median)) bandStats.median = median;
}
if (["string", "number"].includes(typeof gdalMetadata.STATISTICS_STDDEV)) {
const stddev = Number(gdalMetadata.STATISTICS_STDDEV);
if (!isNaN(stddev)) bandStats.stddev = stddev;
}
}
return bandStats;
};