Skip to content

Commit beffafa

Browse files
committed
updated
1 parent 3df451e commit beffafa

File tree

3 files changed

+68
-34
lines changed

3 files changed

+68
-34
lines changed

Diff for: index.js

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const xpath = require('xpath');
21
const { getDecoder } = require('geotiff/dist/compression');
3-
const { parseXml } = require('geotiff/dist/globals');
42

53
// took this from geotiff package
64
function sum(array, start, end) {
@@ -52,22 +50,14 @@ async function getStats(image, debug){
5250
let min = undefined;
5351
let max = undefined;
5452

55-
// try to get min and max via GDAL Metadata
56-
if (fd.GDAL_METADATA) {
57-
const string = fd.GDAL_METADATA;
58-
const xmlDom = parseXml(string.substring(0, string.length - 1));
59-
const evaluator = xmlDom.evaluate ? xmlDom : xpath;
60-
const result = evaluator.evaluate(`GDALMetadata/Item`, xmlDom, null, 6, null);
61-
for (let i = 0; i < result.snapshotLength; ++i) {
62-
const node = result.snapshotItem(i);
63-
if (node.getAttribute('sample') == bandIndex) {
64-
const nodeName = node.getAttribute('name');
65-
if (nodeName === "STATISTICS_MAXIMUM") {
66-
max = parseFloat(node.textContent);
67-
} else if (nodeName === "STATISTICS_MINIMUM") {
68-
min = parseFloat(node.textContent);
69-
}
70-
}
53+
const gdalMetadata = image.getGDALMetadata(bandIndex);
54+
if (debug) console.log("gdalMetadata:", gdalMetadata);
55+
if (gdalMetadata) {
56+
if (typeof gdalMetadata.STATISTICS_MAXIMUM !== 'undefined') {
57+
max = parseFloat(gdalMetadata.STATISTICS_MAXIMUM);
58+
}
59+
if (typeof gdalMetadata.STATISTICS_MINIMUM !== 'undefined') {
60+
min = parseFloat(gdalMetadata.STATISTICS_MINIMUM);
7161
}
7262
}
7363

Diff for: package-lock.json

+58-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "geotiff-stats",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "Get Statistics from a Large GeoTIFF while Using a Low Amount of Memory",
55
"main": "index.js",
66
"scripts": {
@@ -27,7 +27,7 @@
2727
"homepage": "https://github.com/GeoTIFF/geotiff-stats#readme",
2828
"devDependencies": {
2929
"chai": "^4.2.0",
30-
"geotiff": "^1.0.0-beta.6",
30+
"geotiff": "^1.0.0-beta.7",
3131
"mocha": "^7.0.0"
3232
},
3333
"dependencies": {}

0 commit comments

Comments
 (0)