[GIS] How to read the TIFFTAG_DATETIME using GDAL in Python

gdal

I am currently using GDAL from Python to read and transform coordinates and that works well. I would now like to be able to read some of the none geographic tags, for example, TIFFTAG_DATETIME using GDAL. I have searched the net but have been unable to find any examples. Can anyone help?

Best Answer

You can install the GDAL library from OSGEO here: http://www.osgeo.org/ , there are also nice Windows binaries located at here thanks to Tamas Szekeres. Just make sure you install the right version for the version of Python your running.

In your Python code you can import the library like so:

from osgeo import gdal

Then in your code body, you can get a reference to you raster, say, by iterating over a folder of tif's like below...

...
for raster in glob.glob(rootdir + "*.tif"):
...

Then invoke GDAL to open the raster and get a 'handle' to the data source like:

ds = gdal.Open(raster, 0) 

Use "GetMetadataItem" method to pick out the metadata item you're interested in like so:

print ds.GetMetadataItem("TIFFTAG_DATETIME")

You can review other metadata tags here: http://www.gdal.org/gdal_datamodel.html

Close the raster dataset

ds = None