1

I am trying to extract Metadata field from a TIFF file using GeoTools in Java, since I can't use GDAL to achieve that on the deployment platform.

I downloaded a TIFF sample file and used gdalinfo command from shell, getting this output:

Driver: GTiff/GeoTIFF
Files: path\to\file_example_TIFF_1MB.tiff
Size is 650, 434
Metadata:
  TIFFTAG_DOCUMENTNAME=/home/user/Desktop/www/file ex/files/grafa/tiff/file_example_TIFF_1MB.tiff
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_XRESOLUTION=72.009003
  TIFFTAG_YRESOLUTION=72.009003
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  434.0)
Upper Right (  650.0,    0.0)
Lower Right (  650.0,  434.0)
Center      (  325.0,  217.0)
Band 1 Block=650x64 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA
Band 2 Block=650x64 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA
Band 3 Block=650x64 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA
Band 4 Block=650x64 Type=Byte, ColorInterp=Alpha

I was able to fetch every other field using GeoTools, but I can't retrieve the Metadata field.

Is there a way to do it?

1 Answer 1

1

If you're using GeoTiffReader then you can call getMetadata() to get a GeoTiffIIOMetadataDecoder which you can use to access those metadata fields.

If you know the exact metadata tags you want to extract then you can look up their TIFF tag codes using a site like https://www.awaresystems.be/imaging/tiff/tifftags.html and call getAsciiTIFFTag() with the code. For example, if you wanted the document name then you could call getAsciiTIFFTag("269").

If you don't care about specific tags or just want to get everything then you can call getRootNode() on your GeoTiffIIOMetadataDecoder to get an IIOMetadataNode which you can use to traverse the metadata tree yourself. GeoTools provides the IIOMetadataDumper class that you can use to print all the metadata as XML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.