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
878 stars 183 forks source link

Get Corner Coordinates #287

Closed robertowiestifsul closed 2 years ago

robertowiestifsul commented 2 years ago

Hello, I'm using the code below to read information from a file and I can get the corner coordinates from the TIFF query in image metadata. How do I do this using geotiff?

const fetch = require('node-fetch')
const GeoTIFF = require('geotiff');
const { fromUrl, fromUrls, fromArrayBuffer, fromBlob } = GeoTIFF;

(async function () {
    const someUrl = '621c9431e3ed2311cf634888.tiff'
    const response = await fetch(someUrl);
    const arrayBuffer = await response.arrayBuffer();
    const tiff = await fromArrayBuffer(arrayBuffer);
    const image = await tiff.getImage();
    //const width = image.getWidth();
    //console.log(image);
    console.log(image.getGDALMetadata());

    // ...
})()

when using image.getGDALMetadata() is returning null

constantinius commented 2 years ago

Hi @robertowiestifsul

On the image object theres a couple of methods that could be useful, depending on the type of georeferencing of your image.

I think the getBoundingBox method is what you are looking for. Alternatively, the getOrigin in conjunction with getResolution and getWidth/getHeight should also give you results.

I'll close this issue, please reopen if a question remains.