|
1 |
| -const xpath = require('xpath'); |
2 | 1 | const { getDecoder } = require('geotiff/dist/compression');
|
3 |
| -const { parseXml } = require('geotiff/dist/globals'); |
4 | 2 |
|
5 | 3 | // took this from geotiff package
|
6 | 4 | function sum(array, start, end) {
|
@@ -52,22 +50,14 @@ async function getStats(image, debug){
|
52 | 50 | let min = undefined;
|
53 | 51 | let max = undefined;
|
54 | 52 |
|
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); |
71 | 61 | }
|
72 | 62 | }
|
73 | 63 |
|
|
0 commit comments