GeoTIFF GDAL – Running gdalinfo on Partial GeoTIFF Files

gdalinfogeotiff-tiffpixel

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.

Best Answer

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.

Related Question