as shown in the below posted code, i am processing a tiff file. the img
object in the inner-most promise contains some data in a form of key-value.
the object img.fileDirectory.GDAL_METADATA
contains the data posted below.
now my question is, as i would like to have access to STATISTICS_MAXIMUM
,STATISTICS_MEAN
,…etc. how can i have access to contents shown in GDALMetadata
GDALMetadata
<GDALMetadata>
<Item name="STATISTICS_MAXIMUM" sample="0">21.122838228436</Item>
<Item name="STATISTICS_MEAN" sample="0">1.2389914218174</Item>
<Item name="STATISTICS_MINIMUM" sample="0">-4.6630500033646</Item>
<Item name="STATISTICS_STDDEV" sample="0">2.0382729681586</Item>
</GDALMetadata>
code:
response.on('close', async()=>{
console.log('Retrieved all data');
readFile("./test-1.tiff")
.then((data)=>{
dataAsArrayBuffer = data.buffer
fromArrayBuffer(dataAsArrayBuffer)
.then((geoTIFF)=>{
geoTIFF.getImage()
.then((img)=> {
console.log(img.fileDirectory.GDAL_METADATA);//<==============
console.log(img.getWidth(), img.getHeight(), img.getSamplesPerPixel());
})
.catch((e)=>console.log("img.errorMessage:",e))
})
.catch((e)=> console.log("geoTIFF.errorMessage:",e))
})
.catch((e)=> console.log("data.errorMessage:",e))
});
2
Answers
Use a DOMParser
Parsing HTML/XML on server side with Node.js. can be done with parsers such as cheerio
Try this, it loads your string, finds all
Item
elements, loops them and gets text value. You can then construct results object according to your needs: