2

I'm trying to determine the pixel size and corner coordinates of a GeoTIFF file in a cloud service that I'm developing, before uploading the file completely. So my plan is to upload the first 10kB or so and then run gdalinfo on the partial file.

Unfortunately this seems to work on some files and fail on others. Can the header info read by gdalinfo be spread over large portions of the file so that I can't expect to be able to do this? Is there any other possibility?

I have to adapt to any GeoTIFF files that my users might provide. So I can't convert to a cloud-optimized GeoTIFF.

1

1 Answer 1

4

The TIFF metadata can indeed be spread in many places. Especially if you create overviews with gdaladdo the overviews and corresponding metadata are always written close to the end of the TIFF file.

If you want to develop your own system I would still recommend to have a look at some of the existing open source solutions. Many of those are listed in https://www.cogeo.org/.

Cloud Optimized GeoTIFF (COG) https://www.cogeo.org/in-depth.html is a TIFF variant that is developed just for your use case. You can convert your existing images by using the GDAL COG driver https://gdal.org/drivers/raster/cog.html.

3
  • Thanks, but I need to adapt to any GeoTIFF my users might provide (edited my question). Sounds reasonable that the rasters giving me problems indeed have overviews close to the end of the file. Maybe I can develop a small application using libtiff that reads the very first metadata providing pixel size and corner coordinates only, not caring about the rest. Can that basic metadata at least be guaranteed to be in the beginning of the file? And do you know if libtiff would allow me to read partial metadata like that? Commented Oct 3, 2021 at 7:00
  • 1
    I guess that you should read the TIFF specification adobe.io/content/dam/udp/en/open/standards/tiff/TIFF6.pdf. It seems to me that all that is guaranteed is the header in the first eight bytes. The header contains pointer to the first IDF, but: The offset (in bytes) of the first IFD. The directory may be at any location in the file after the header but must begin on a word boundary. In particular, an Image File Directory may follow the image data it describes. Readers must follow the pointers wherever they may lead. And at the end of IDF is the pointer to the next IDF.
    – user30184
    Commented Oct 3, 2021 at 20:30
  • Thanks, I will try to read the header and follow the pointers using Javascript instead. Commented Oct 8, 2021 at 8:13

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.