到目前为止,我找不到改变TIFF文件中的GeoTiff-TAG的方法。 我的操作系统是Linux Lubuntu 18.04,我使用的是Python3.x。 只是EXIF-TAG可以通过各种方法进行更改。
对于读写EXIF标签,我可以使用例如:
尤其是python模块似乎对GeoTiff-Tag视而不见,即它们仅读取(和写入)EXIF-TAG,但不读取(或写入)GeoTiff-Tag。 使用exiftool,我至少可以读取和打印GeoTiff-TAG以及其他标签。 例如,通过我的TIFF文件的exiftool进行的控制台输出(其中还包括GeoTiff-Tags)将是:
输入:
exiftool -D -G -a -u -U -f "newfile.tif"
输出:
[ExifTool] - ExifTool Version Number : 10.80
[File] - File Name : newfile.tif
[File] - Directory : .
[File] - File Size : 1503 kB
[File] - File Modification Date/Time : 2019:12:19 17:32:17+01:00
[File] - File Access Date/Time : 2019:12:19 17:32:17+01:00
[File] - File Inode Change Date/Time : 2019:12:19 17:32:17+01:00
[File] - File Permissions : rw-rw-r--
[File] - File Type : TIFF
[File] - File Type Extension : tif
[File] - MIME Type : image/tiff
[File] - Exif Byte Order : Little-endian (Intel, II)
[File] - Current IPTC Digest : 79ffcf282ca6974ff99640a7421b40b7
[EXIF] 256 Image Width : 1148
[EXIF] 257 Image Height : 1337
[EXIF] 258 Bits Per Sample : 8
[EXIF] 259 Compression : Uncompressed
[EXIF] 262 Photometric Interpretation : RGB Palette
[EXIF] 273 Strip Offsets : (Binary data 1390 bytes, use -b option to extract)
[EXIF] 274 Orientation : Horizontal (normal)
[EXIF] 277 Samples Per Pixel : 1
[EXIF] 278 Rows Per Strip : 7
[EXIF] 279 Strip Byte Counts : (Binary data 954 bytes, use -b option to extract)
[EXIF] 282 X Resolution : 1
[EXIF] 283 Y Resolution : 1
[EXIF] 284 Planar Configuration : Chunky
[EXIF] 296 Resolution Unit : None
[EXIF] 305 Software : IMAGINE TIFF Support.Copyright 1991 - 1999 by ERDAS, Inc. All Rights Reserved.@(#)$RCSfile: etif.c $ $Revision: 1.11 $ $Date$
[EXIF] 320 Color Map : (Binary data 1536 bytes, use -b option to extract)
[EXIF] 339 Sample Format : Unsigned
[EXIF] 33550 Pixel Scale : 30 30 0
[EXIF] 33922 Model Tie Point : 0 0 0 1514925 1583985 0
[IPTC] 25 Keywords : word
[IPTC] 0 Application Record Version : 4
[GeoTiff] 1 Geo Tiff Version : 1.1.0
[GeoTiff] 1024 GT Model Type : Projected
[GeoTiff] 1025 GT Raster Type : Pixel Is Area
[GeoTiff] 1026 GT Citation : IMAGINE GeoTIFF Support.Copyright 1991 - 2001 by ERDAS, Inc. All Rights Reserved.@(#)$RCSfile: egtf.c $ $Revision: 1.11.2.3 $ $Date: 2004/11/24 09:12:56EST $.Projection Name = USA_Contiguous_Albers_Equal_Area_Conic_USGS_version.Units = meters.GeoTIFF Units = meters
[GeoTiff] 2048 Geographic Type : NAD83
[GeoTiff] 3072 Projected CS Type : User Defined
[GeoTiff] 3073 PCS Citation : IMAGINE GeoTIFF Support.Copyright 1991 - 2001 by ERDAS, Inc. All Rights Reserved.@(#)$RCSfile: egtf.c $ $Revision: 1.11.2.3 $ $Date: 2004/11/24 09:12:56EST $.Projection = Albers Conical Equal Area
[GeoTiff] 3074 Projection : User Defined
[GeoTiff] 3075 Proj Coord Trans : Albers Equal Area
[GeoTiff] 3076 Proj Linear Units : Linear Meter
[GeoTiff] 3078 Proj Std Parallel 1 : 29.5
[GeoTiff] 3079 Proj Std Parallel 2 : 45.5
[GeoTiff] 3081 Proj Nat Origin Lat : 23
[GeoTiff] 3082 Proj False Easting : 0
[GeoTiff] 3083 Proj False Northing : 0
[GeoTiff] 3088 Proj Center Long : -96
[Composite] - Image Size : 1148x1337
[Composite] - Megapixels : 1.5
然后,我尝试更改/删除例如GeoTiff-TAG“投影”,它会在不进行任何更改的情况下引发以下警告消息: 输入:
exiftool "-Projection=" "newfile.tif"
输出:
Warning: Sorry, Projection is not writable. Nothing to do.
在互联网上搜索时,我发现了其他库和程序包,这些库和程序包可能会对我有所帮助,但到目前为止没有用,因为我没有找到文档,或者它没有用:
对于后一种方法gdal_edit和gdal_translate,我尝试了以下操作,但没有任何效果(即使没有任何错误消息):
gdal_edit.py -mo "3075=Custom" "newfile.tif"
gdal_edit.py -mo "ProjCoordTrans=Custom" "newfile.tif"
gdal_translate -mo "3075=Custom" "newfile.tif" "newfile_2.tif"
gdal_translate -mo "ProjCoordTrans=Custom" "newfile.tif" "newfile_2.tif"
如您所见,在示例中,我尝试将名为“ ProjCoordTrans”的GeoTIFF标签编号3075修改为Costum字符串。在执行这4个命令中的任何一个时,都不会引发任何错误,但随后通过
检查TIFF标签exiftool -D -G -a -u -U -f -s "newfile.tif"
我发现相同的TAG仍然保持不变。
我想知道是否有可能更改GeoTiff标签。一定有可能。
答案 0 :(得分:1)
我在exiftool本身的项目页面上找到了answer。 此后,我将总结在页面作者Phil Harvey的帮助下发现的内容。
要将所有GeoTiff标签从一个文件复制到另一个文件,请执行以下操作:
exiftool -tagsfromfile SRCFILE -GeoTiffDirectory -GeoTiffDoubleParams -GeoTiffAsciiParams DSTFILE
就可以了。 我假设这些伪标记由所有sub-GeoTiff-TAG中的exiftools拆分,因为python中的其他工具会将这些伪标记及其相关编号打印为TAG。 能够显示这3个通用Geotiff-TAG的Python软件包
例如:
import PIL
import tifffile as tf
from skimage.external import tifffile as sk_tf
通过在示例TIFF上应用我的python脚本使用PILLOW(PIL)的示例输出为:
...
** GENERIC APPROACH USING PILLOW-package **
TAG number: '254'
TAG name: 'NewSubfileType'
TAG value: '(0,)'
TAG number: '256'
TAG name: 'ImageWidth'
TAG value: '(2388,)'
TAG number: '257'
TAG name: 'ImageLength'
TAG value: '(1651,)'
TAG number: '258'
TAG name: 'BitsPerSample'
TAG value: '(8,)'
TAG number: '259'
TAG name: 'Compression'
TAG value: '(1,)'
TAG number: '262'
TAG name: 'PhotometricInterpretation'
TAG value: '(1,)'
TAG number: '270'
TAG name: 'ImageDescription'
TAG value: '('{"shape": [1651, 2388]}',)'
TAG number: '274'
TAG name: 'Orientation'
TAG value: '(1,)'
TAG number: '277'
TAG name: 'SamplesPerPixel'
TAG value: '(1,)'
TAG number: '278'
TAG name: 'RowsPerStrip'
TAG value: '(1651,)'
TAG number: '282'
TAG name: 'XResolution'
TAG value: '((1, 1),)'
TAG number: '283'
TAG name: 'YResolution'
TAG value: '((1, 1),)'
TAG number: '284'
TAG name: 'PlanarConfiguration'
TAG value: '(1,)'
TAG number: '296'
TAG name: 'ResolutionUnit'
TAG value: '(1,)'
TAG number: '305'
TAG name: 'Software'
TAG value: '('tifffile.py',)'
TAG number: '339'
TAG name: 'SampleFormat'
TAG value: '(1,)'
TAG number: '33550'
TAG name: 'ModelPixelScaleTag'
TAG value: '(30.0, 30.0, 0.0)'
TAG number: '33922'
TAG name: 'ModelTiepointTag'
TAG value: '(0.0, 0.0, 0.0, 737125.0, 4328658.0, 0.0)'
TAG number: '34735'
TAG name: 'GeoKeyDirectoryTag'
TAG value: '(1, 1, 0, 15, 1024, 0, 1, 1, 1025, 0, 1, 1, 1026, 34737, 266, 0, 2048, 0, 1, 4269, 3072, 0, 1, 32767, 3073, 34737, 197, 266, 3074, 0, 1, 32767, 3075, 0, 1, 11, 3076, 0, 1, 9001, 3078, 34736, 1, 0, 3079, 34736, 1, 1, 3081, 34736, 1, 2, 3082, 34736, 1, 3, 3083, 34736, 1, 4, 3088, 34736, 1, 5)'
TAG number: '34736'
TAG name: 'GeoDoubleParamsTag'
TAG value: '(29.5, 45.5, 23.0, 0.0, 0.0, -96.0)'
TAG number: '34737'
TAG name: 'GeoAsciiParamsTag'
TAG value: '('IMAGINE GeoTIFF Support\nCopyright 1991 - 2001 by ERDAS, Inc. All Rights Reserved\n@(#)$RCSfile: egtf.c $ $Revision: 1.11.2.3 $ $Date: 2004/11/24 09:12:56EST $\nProjection Name = USA_Contiguous_Albers_Equal_Area_Conic_USGS_version\nUnits = meters\nGeoTIFF Units = meters|IMAGINE GeoTIFF Support\nCopyright 1991 - 2001 by ERDAS, Inc. All Rights Reserved\n@(#)$RCSfile: egtf.c $ $Revision: 1.11.2.3 $ $Date: 2004/11/24 09:12:56EST $\nProjection = Albers Conical Equal Area|',)'
...
要单独更改Projection标签,当前必须手动编辑GeoTiffDirectory数据。
首先将(二进制)数据写入文件:
exiftool -geotiffdirectory -b FILE.tif > out.dat
然后找到例如的偏移量投影值,例如:
exiftool FILE.tif -v3 | grep -A 2 Projection -
| 9) Projection = 16017
| - Tag 0x0c02 (2 bytes, int16u[1]):
| 0056: 3e 91 [>.]
->在out.dat中编辑字节0x56和0x57以更改为所需的投影,然后将修改后的GeoTiff目录放回TIFF文件:
exiftool "-geotiffdirectory<=out.dat" FILE.tif
不过,值得注意的是,更改了3个至关重要的汇总GeoTIFF-Tag,而不是试图通过修改上述二进制文件并将其重新分配给相关TIFF来操纵单个GeoTIFF-TAG。 ,可能会更有效。
为了完整起见,这3个GeoTIFF标签为:
尽管如此,通过更改二进制文件中的一个特定GeoTIFF-Tag,也有可能更新新TIFF中的3个至关重要的GeoTIFF-summary-Tag。 我还没有尝试过。
如果您需要为这些方法添加一些其他信息或经验(对您有用)等,请告诉我。
欢呼