我将一些 tiff 文件转换为 jp2,我想将其元数据复制到新文件上。以下是来自元数据查看器的元数据示例:
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)
我正在使用 pyexiftool 库,我可以使用以下代码检索元数据:
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}
现在我想使用以下代码为 .jp2 图像创建这些新标签:
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}")
我得到以下信息:
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
标签确实不存在,但我不知道如何从这里继续,有什么想法吗?
Exiftool 无法编写单独的 GeoTiff 标签。它只能将它们复制为一个块。
此外,GeoTiff 标签只能存在于 TIFF 文件中,因此无法复制到 JP2 文件中。请参阅支持的文件类型表。
您需要在 XMP 中找到一个新位置,并将标签复制到这些新位置。据我所知,该命名空间中没有任何相应的标签,因此您必须重新调整一些现有标签的用途或尝试创建自己的专有标签来保存数据。有关创建标签的信息,请参阅示例配置文件。