geotiff.js icon indicating copy to clipboard operation
geotiff.js copied to clipboard

Writing non-byte number types

Open energyaccessexplorer opened this issue 5 years ago • 4 comments

Hello! I am trying to write a TIF file with a Float32 raster.

This works like a charm:

async function raster_to_tiff(raster) {
  const metadata = {
    height: 634,
    width: 604
  };
  const arrayBuffer = await GeoTIFF.writeArrayBuffer(raster, metadata);
  let blob = new Blob([arrayBuffer], { type: "application/octet-stream;charset=utf-8" });
  fake_download(URL.createObjectURL(blob)); // fake_download is just a trick that simulates... you get it.

  return blob;
};

when raster is a Uint8Array, but if I pass a Float32Array, the resulting file shows: Type=Byte (0-255) according to gdalinfo.

I have peeked at this with no luck. Is wriing Float32 TIF supported? Am I missing something on metadata?

Thank you for geotiff!

energyaccessexplorer avatar Sep 12 '19 20:09 energyaccessexplorer

Hi @energyaccessexplorer

Currently, the TIFF writing is currently only capable of dealing with Byte data, other datatypes such as Float 32 will probably be supported at some point in the future.

@DanielJDufour do you already have plans for that functionality?

constantinius avatar Sep 16 '19 09:09 constantinius

Awesome, @energyaccessexplorer ! I'm glad to see that it's working for Uint8Array. Unfortunately, geotiff.js (and specifically the geotiffwriter.js doesn't support writing anything other than Uint8Arrays of values. However, adding support for writing a Float32 Raster would be super valueable. Want to work on it? :-)

You would have to adjust a few lines in this area of the code: https://github.com/geotiffjs/geotiff.js/blob/master/src/geotiffwriter.js#L255 where the values are being written. I believe the metadata writing functions could stay the same, but I'm not 100% sure.

DanielJDufour avatar Sep 17 '19 03:09 DanielJDufour

@DanielJDufour. I submitted a pull request. https://github.com/geotiffjs/geotiff.js/pull/106 It worked on one small float32Array. Does it look correct?

m0ose avatar Oct 01 '19 16:10 m0ose

@m0ose , awesome! I'm looking at your PR now!

DanielJDufour avatar Oct 06 '19 13:10 DanielJDufour