Is there a way to find the size (in bytes) of the header information in a GeoTIFF file using Python? I am not trying to read the header (I know I can use gdalinfo
for this) but rather to figure out what position I need to skip to in order to read the file as binary. This is because I am interested in testing numpy memory-mapped arrays for reading portions of an image from the disk. I would like to test this versus the gdal builtin ReadAsArray()
method because I enjoy the flexibility of numpy indexing.
GeoTIFF Header Size – Determining Size of GeoTIFF Header with Python
gdalgeotiff-tiffnumpypython
Best Answer
Check out tifffile, which is a Python package to read and write image data from and to TIFF files.
So far, this is no different than either rasterio or GDAL.
To answer your question, you can get the byte offset and size from the
page.is_contiguous
property, then read it with regular numpy or any other tool that can read contiguous data: