I convert some tiff files to jp2 and I want to copy their metadata on the new files. Here is an example of the metadata from a metadata viewer:
Raster to World Matrix:
Units: Meters
amx[ 0]=0.0499999999999964, amx[ 1]= 0, amx[ 2]= 395680.65
amx[ 3]= 0, amx[ 4]= -0.05, amx[ 5]= 4199400
395680.65 , 4199400
396000 , 4199400
396000 , 4198800
395680.65 , 4198800
Geotiff_Information:
Version: 1
Key_Revision: 1.0
Tagged_Information:
ModelTiepointTag (2,3):
0 0 0
395680.65 4199400 0
ModelPixelScaleTag (1,3):
0.05 0.05 0
End_Of_Tags.
Keyed_Information:
GTModelTypeGeoKey (Short,1): ModelTypeProjected
GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
GTCitationGeoKey (Ascii,22): "PCS Name = Greek_Grid"
GeographicTypeGeoKey (Short,1): GCS_GGRS87
GeogCitationGeoKey (Ascii,86): "GCS Name = GCS_GGRS_1987|Datum = D_GGRS_1987|Ellipsoid = GRS_1980|Primem = Greenwich|"
GeogGeodeticDatumGeoKey (Short,1): Unknown-6121
GeogPrimeMeridianGeoKey (Short,1): PM_Greenwich
GeogAngularUnitsGeoKey (Short,1): Angular_Degree
GeogAngularUnitSizeGeoKey (Double,1): 0.0174532925
GeogEllipsoidGeoKey (Short,1): Ellipse_GRS_1980
GeogSemiMajorAxisGeoKey (Double,1): 6378137
GeogInvFlatteningGeoKey (Double,1): 298.257222
GeogPrimeMeridianLongGeoKey (Double,1): 0
ProjectedCSTypeGeoKey (Short,1): PCS_GGRS87_Greek_Grid
PCSCitationGeoKey (Ascii,410): "ESRI PE String = PROJCS["Greek_Grid",GEOGCS["GCS_GGRS_1987",DATUM["D_GGRS_1987",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",24.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]"
ProjLinearUnitsGeoKey (Short,1): Linear_Meter
End_Of_Keys.
End_Of_Geotiff.
PCS = 2100 (GGRS87 / Greek Grid)
Projection = 19930 (Greek Grid)
Projection Method: CT_TransverseMercator
ProjNatOriginLatGeoKey: 0.000000 ( 0d 0' 0.00"N)
ProjNatOriginLongGeoKey: 24.000000 ( 24d 0' 0.00"E)
ProjScaleAtNatOriginGeoKey: 0.999600
ProjFalseEastingGeoKey: 500000.000000 m
ProjFalseNorthingGeoKey: 0.000000 m
GCS: 4121/GGRS87
Datum: 6121/Greek Geodetic Reference System 1987
Ellipsoid: 7019/GRS 1980 (6378137.00,6356752.31)
Prime Meridian: 8901/Greenwich (0.000000/ 0d 0' 0.00"E)
Projection Linear Units: 9001/metre (1.000000m)
Corner Coordinates:
Upper Left ( 395680.650, 4199400.000)
Lower Left ( 395680.650, 4199399.950)
Upper Right ( 395680.700, 4199400.000)
Lower Right ( 395680.700, 4199399.950)
Center ( 395680.675, 4199399.975)
I am using the pyexiftool library and I can retrieve the metadata with the following code:
with exiftool.ExifToolHelper() as et:
metadata_tiff = et.get_metadata(tiff_path)
{'GeoTiff:GeoTiffVersion': '1.1.0', 'GeoTiff:GTModelType': 1, 'GeoTiff:GTRasterType': 1, 'GeoTiff:GTCitation': 'PCS Name = Greek_Grid', 'GeoTiff:GeographicType': 4121, 'GeoTiff:GeogCitation': 'GCS Name = GCS_GGRS_1987|Datum = D_GGRS_1987|Ellipsoid = GRS_1980|Primem = Greenwich|', 'GeoTiff:GeogGeodeticDatum': 6121, 'GeoTiff:GeogPrimeMeridian': 8901, 'GeoTiff:GeogAngularUnits': 9102, 'GeoTiff:GeogAngularUnitSize': 0.0174532925199433, 'GeoTiff:GeogEllipsoid': 7019, 'GeoTiff:GeogSemiMajorAxis': 6378137, 'GeoTiff:GeogInvFlattening': 298.257222101, 'GeoTiff:GeogPrimeMeridianLong': 0, 'GeoTiff:ProjectedCSType': 2100, 'GeoTiff:PCSCitation': 'ESRI PE String = PROJCS["Greek_Grid",GEOGCS["GCS_GGRS_1987",DATUM["D_GGRS_1987",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",24.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]', 'GeoTiff:ProjLinearUnits': 9001}
and now that I want to create these new tags to the .jp2 image with the following code:
import exiftool
from exiftool.exceptions import ExifToolExecuteError
try:
et.set_tags(files=[jp2_path], tags=geotiff_keys)
except ExifToolExecuteError as e:
print(f"Stdout: {e.stdout}")
print(f"Stderr: {e.stderr}")
I get the following:
Stdout:
Stderr: Warning: Sorry, GeoTiff:GeoTiffVersion doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GTModelType doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GTRasterType doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GTCitation doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeographicType doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogCitation doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogGeodeticDatum doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogPrimeMeridian doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogAngularUnits doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogAngularUnitSize doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogEllipsoid doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogSemiMajorAxis doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogInvFlattening doesn't exist or isn't writable
Warning: Sorry, GeoTiff:GeogPrimeMeridianLong doesn't exist or isn't writable
Warning: Sorry, GeoTiff:ProjectedCSType doesn't exist or isn't writable
Warning: Sorry, GeoTiff:PCSCitation doesn't exist or isn't writable
Warning: Sorry, GeoTiff:ProjLinearUnits doesn't exist or isn't writable
Nothing to do.
Exception ignored in: <function ExifTool.__del__ at 0x000001A8D8878860>
Traceback (most recent call last):
File "C:\Users\avenianakis\AppData\Local\Programs\Python\Python312\Lib\site-packages\exiftool\exiftool.py", line 321, in __del__
File "C:\Users\avenianakis\AppData\Local\Programs\Python\Python312\Lib\site-packages\exiftool\helper.py", line 166, in terminate
File "C:\Users\avenianakis\AppData\Local\Programs\Python\Python312\Lib\site-packages\exiftool\exiftool.py", line 904, in terminate
File "C:\Users\avenianakis\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1209, in communicate
File "C:\Users\avenianakis\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1610, in _communicate
File "C:\Users\avenianakis\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 992, in start
RuntimeError: can't create new thread at interpreter shutdown
The tags indeed do not exist but I do not know how to move on from here, any ideas?
Exiftool doesn't have the ability to write individual GeoTiff tags. It can only copy them as a block.
Additionally, GeoTiff tags can only exist in a TIFF file, so they can't be copied to a JP2 file. See the Supported File Types table.
You'll need to figure out a new location in XMP and copy the tags to those new locations. There aren't any corresponding tags in that namespace AFAIK, so you would have to repurpose some existing tags or try to create your own proprietary tags to hold the data. See the example config file for info on creating tags.