Search code examples
pythonexifqgisgeotiff

How to add GeoTIFF tags into EXIF image data in Python?


I wrote a script that gets an image as input and then convert it to tiff format. Now I need to add some GeoTIFF tags into the EXIF image data (e.g. pixel size, coordinates, etc) so I could work with this image in QGIS.

If Python doens't have any lib that can handle this I could migrate this script to C++. Anny suggestion?


Solution

  • You need use gdal library.

    import gdal
    
    gdal.AllRegister()
    
    inputImagePath = "your geotiff"
    inputdataset = gdal.Open(inputImagePath)
    
    inputdataset.SetMetadataItem("TEST","TEST METADATA")
    
    inputdataset = None
    

    this code add a metadata item "TEST" in the image.