Skip to content

missing DOUBLE case metadata properties on geotiffwriter #476

@jo-chemla

Description

@jo-chemla

Context is I'm just trying to export geotiffs with EPSG:4326 CRS, and then importing/exporting the result which yields to this error.

I'm trying to read an input geotiff via fromBlob, edit its raster values, and export via writeArrayBuffer but exporting yields the below errors:

[geotiff.js] couldn't get TIFFTagLocation for GeogSemiMajorAxisGeoKey [geotiffwriter.js:469:17](http://localhost:5173/node_modules/geotiff/dist-module/geotiffwriter.js)
[geotiff.js] couldn't get TIFFTagLocation for GeogInvFlatteningGeoKey

These errors redirect to these lines:

if (fieldTagTypes[KeyID] === 'SHORT') {
Count = 1;
TIFFTagLocation = 0;
valueOffset = metadata[geoKey];
} else if (geoKey === 'GeogCitationGeoKey') {
Count = metadata.GeoAsciiParams.length;
TIFFTagLocation = Number(name2code.GeoAsciiParams);
valueOffset = 0;
} else {
console.log(`[geotiff.js] couldn't get TIFFTagLocation for ${geoKey}`);
}

Could it be that GeogSemiMajorAxisGeoKey and GeogInvFlatteningGeoKey are DOUBLE according to the geotiff spec and

  • mappings should be added in file globals.js to the fieldTagTypes object, where 2057 and 2059 should be DOUBLE?
  • and the case fieldTagTypes[KeyID] === 'DOUBLE' should be handled properly in the GeoKeyDirectory object? Is it simply a matter of Count = 2 in the DOUBLE case?

For reference, here is an extract of the read/write code, parsing geoMetadata on read and exploding it into the metadata object passed to writeArrayBuffer.

  const tiff = await fromBlob(file);
  const image = await tiff.getImage();
  const rasters = await image.readRasters({ interleave: true });

   const geoMetadata = {
      geoKeys: image.getGeoKeys(),
      fileDirectory: image.fileDirectory,
    }

  const { ModelPixelScale, ModelTiepoint, ImageWidth: width, ImageLength: height } = geoMetadata.fileDirectory;
  const metadata = {
    // GeographicTypeGeoKey: geoMetadata.geoKeys.GeographicTypeGeoKey,
    width,
    height,
    ModelPixelScale,
    ModelTiepoint,
    // ...geoMetadata.fileDirectory
    ...(geoMetadata.geoKeys), 
    // couldn't get TIFFTagLocation for GeogSemiMajorAxisGeoKey, GeogInvFlatteningGeoKey
  };
  const metadata_ = JSON.parse(JSON.stringify(metadata)); // deep clone copy
  const arrayBuffer = await writeArrayBuffer(raster, metadata_);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions