geotiffjs / geotiff.js

geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.
https://geotiffjs.github.io/
MIT License
860 stars 181 forks source link

write statistics #327

Open DanielJDufour opened 1 year ago

DanielJDufour commented 1 year ago

Would this be helpful? Internally, writeArrayBuffer would call another function that creates the <GDALMetadata> xml file and adds that as a GDAL_METADATA tiff tag to the output file.

import { writeArrayBuffer } = "geotiff";

writeArrayBuffer(data, {
    // an array of stats objects
    // each object represents that stats for that band (by array index)
    gdalStats: [
        {
          STATISTICS_MAXIMUM: 255,
          STATISTICS_MEAN: 72.031078729883,
          STATISTICS_MINIMUM: 0,
          STATISTICS_STDDEV: 38.825421707699,
          STATISTICS_VALID_PERCENT: 100
        },
        // you can also pass in statistics as strings
        // getGDALMetadata returns raw strings
        // and a user might want to return high-precision numerical strings
       //  that are more precise than what JavaScript support
        {
          STATISTICS_MAXIMUM: "255",
          STATISTICS_MEAN: "113.60373423227124325",
          STATISTICS_MINIMUM: "0",
          STATISTICS_STDDEV: "38.825421707699",
          STATISTICS_VALID_PERCENT: "100"
        }
    ]
})