Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing non-byte number types #103

Open
energyaccessexplorer opened this issue Sep 12, 2019 · 4 comments
Open

Writing non-byte number types #103

energyaccessexplorer opened this issue Sep 12, 2019 · 4 comments

Comments

@energyaccessexplorer
Copy link

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!

@constantinius
Copy link
Member

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?

@DanielJDufour
Copy link
Contributor

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.

@m0ose
Copy link

m0ose commented Oct 1, 2019

@DanielJDufour. I submitted a pull request. #106
It worked on one small float32Array. Does it look correct?

@DanielJDufour
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants