geotiff.js
geotiff.js copied to clipboard
Writing non-byte number types
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!
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?
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. I submitted a pull request. https://github.com/geotiffjs/geotiff.js/pull/106 It worked on one small float32Array. Does it look correct?
@m0ose , awesome! I'm looking at your PR now!