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
859 stars 179 forks source link

Writing of multiple images supported? #379

Open aLemonFox opened 1 year ago

aLemonFox commented 1 year ago

Hey, I was wondering how to write multiple 'subfiles' or images. One image works fine following the example in the docs, but I can't really figure out how I would add a second or third dataset as image so I could do tiff.getImage(1).

const values = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const metadata = {
  height: 3,
  width: 3
};
const arrayBuffer = await writeArrayBuffer(values, metadata);
const tiff = await fromArrayBuffer(arrayBuffer);
const image = await tiff.getImage();
const image = await tiff.getImage(1); // not possible now

How would I add another image to this file?

DanielJDufour commented 1 year ago

Hi @aLemonFox , that's a great question! Unfortunately, that's not currently a capability that the geotiffwriter has. Would you be interested in working on a PR?

aLemonFox commented 1 year ago

@DanielJDufour I would love to try and help out, but this is the first time for me working with geotiffs. So I am not really aware of how these files work. I took a look at the code and I am guessing we need to somehow write multiple IFD's to store multiple datasets in the same file? If you could point me in the right direction I might be able to figure something out.

DanielJDufour commented 1 year ago

I think you are on the right path! Could you describe in a little more detail your use case for writing multiple images? Are you simply trying to write simplified overviews of your data? Or are you trying to leverage tiff files ability to store multiple "pages/scans" of a "document"? Just wanting to double check we are talking about the same thing :-)

aLemonFox commented 1 year ago

I have a few 2d datasets all of the same size. All of the metadata is the same. So currently I have multiple standalone .tif files for each dataset. This works fine but based on the getImage() function I thought it might be easier (storage wise) if these datasets are merged into the same file. These files themselves are related to eachother. Each image contains some radar data on a five minute interval so instead of having to load each file independently, I could just call getImage(x) with the images I currently need.