GDAL – How to Set Custom GDAL Tags Using PROFILE=[GDALGeoTIFF]

gdalgeotiff-tiffpython

I am trying to write custom metadata to a Geotiff file using:

if dataset:
driver = gdal.GetDriverByName("GTiff")
dst_ds = driver.CreateCopy('result_tiff', dataset, strict=0,
                           options=["PROFILE=GDALGeoTIFF"]

This will eventually be incoorperated into a Tkinter application where users can add and edit metadata in image files. I read on https://svn.osgeo.org/gdal/tags/1.6.3/gdal/frmts/gtiff/frmt_gtiff.html that GDAL custom tags may be written using PROFILE=GDALGeoTIFF. I haven't found an example of how to do so.

Does anyone have any idea?

Best Answer

How to add metadata into existing TIFF:

from osgeo import gdal
ds = gdal.Open("test.tif", gdal.GA_Update)
ds.SetMetadata({"COUNTRY_CODE": "foo"})
ds = None

Check the result with gdalinfo

gdalinfo test.tif
Driver: GTiff/GeoTIFF
Files: test.tif
Size is 1198, 645
Coordinate System is:
...
Metadata:
  AREA_OR_POINT=Point
  COUNTRY_CODE=foo
...
Related Question