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
866 stars 182 forks source link

Could not get value of geoKey 'GeogSemiMajorAxisGeoKey' #384

Closed ThomasAribart closed 1 year ago

ThomasAribart commented 1 year ago

Hello and thanks for this wonderful lib 🙌

In my GeoTiff, I have the following geoKeys:

geoKeys: {
  GTModelTypeGeoKey: 2,
  GTRasterTypeGeoKey: 1,
  GeographicTypeGeoKey: 4326,
  GeogCitationGeoKey: 'WGS 84',
  GeogAngularUnitsGeoKey: 9102,
  GeogSemiMajorAxisGeoKey: 6378137,
  GeogInvFlatteningGeoKey: 298.257223563
}

When writing my GeoTIFF to a file with writeArrayBuffer and re-opening with fromFile, I get the following error: Could not get value of geoKey 'GeogSemiMajorAxisGeoKey'.

I've tried adding the GeogSemiMajorAxisGeoKey to the metadata options but I get the following error: unknown type of tag: 2057

How can I get this geokey value to be saved and re-used ? Would be glad to help by submitting a PR !

Many thanks !


Note: After digging a bit in the code, I think there's bug in the geotiffwriter, line 434:

// delete GeoKeys from metadata, because stored in GeoKeyDirectory tag
for (const geoKey in geoKeys) {
  if (geoKeys.hasOwnProperty(geoKey)) {
    delete metadata[geoKey];
  }
}

The first intention was probably the following:

for (const geoKey of geoKeys) {
  if (metadata.hasOwnProperty(geoKey)) {
    delete metadata[geoKey];
  }
}