1

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?

3
  • GDAL 1.6.3 is thirteen years old trac.osgeo.org/gdal/wiki/Release/1.6.3-News! Read the current documentation first from gdal.org/drivers/raster/gtiff.html. Gdal_edit gdal.org/programs/gdal_edit.html#gdal-edit is a Python script that can set metadata tags and is probably useful as an example.
    – user30184
    Jan 12, 2023 at 20:45
  • What metadata are you trying to write? The PROFILE creation option only determines where GDAL writes its non standard metadata. If GDALGeoTIFF, the GDAL metadata gets written to the the TIFF file itself in a non standard TIFFTAG (TIFFTAG_GDAL_METADATA ), for BASELINE and GeoTIFF, it will be written to an external aux.xml file.
    – user2856
    Jan 12, 2023 at 21:13
  • Without getting into detail, I am trying to write metdata such as the country code and other info that is specific to my workplace. I am trying to write data to the TIFF file itself, not just to an external aux.xml.
    – Rina Tse
    Jan 13, 2023 at 20:51

1 Answer 1

1

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
...

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.