Open daumann opened 1 year ago
Hello, thank you for posting this important issue. It helps gauge community interest in different features. Unfortunately, it's a current limitation of the writer that it can only write Uint8 values. However, updating the code to support other data types is very achievable. Please let me know if you have the time to write a PR and I can provide some more background. Hope you have a nice rest of your day.
Thanks Daniel for the quick response! Yes I can look into adding that feature. If you could give me some starting points, that would be great!
Hey, great to hear. Here's a few links to the relevant parts:
The main file that does the writing: https://github.com/geotiffjs/geotiff.js/blob/master/src/geotiffwriter.js. I tried to put all the writing functionality in one file to keep things modular (and separate from the reading functionality). It does however use globals.js and utils.js.
This line is currently assuming uint8 data type, but will need to be dynamic depending on nbit value I assume: https://github.com/geotiffjs/geotiff.js/blob/master/src/geotiffwriter.js#L255. I think the other lines in encodeImage will have be refactored as well.
Hopefully this helps a little, but it already seems like you have a good sense of it.
Happy to answer any more questions or help with code review later on.
Best of luck!
Hi, @daumann . I'm sorry. I totally forgot about this old PR until I came across it today: https://github.com/geotiffjs/geotiff.js/pull/106. I think you could definitely build off of it or consult the comments. Let me know if you have any more questions.
@DanielJDufour Here is the PR that adds support for writing uint8, uint16, uint32 and float32: https://github.com/geotiffjs/geotiff.js/pull/366
I also added tests for each new data type (which all pass)
That's awesome! I'll try to review it as soon as I can. Thank you!
@DanielJDufour Quick reminder, so this PR isn't forgotten...
Here is a snippet of the code I am testing with:
Unfortunately this won't work because when inspecting the resulting tiff with
gdalinfo -stats test.tiff -mm
The values have been corrupted:while the Minimum is correct, the Maximum is off (because it exceeds the Uint8 limit).
I tried to change my code by adding
to the metadata but this gives me the following issue when inspecting the result:
Notice that the Type has now changed from Byte to UInt32, but the data does not seem to have been encoded correctly.
Any pointers are very welcome!