如何更改或删除地理标签?

2024-03-29 07:09:20 发布

您现在位置:Python中文网/ 问答频道 /正文

到目前为止,我找不到一种方法来更改TIFF文件中的GeoTiff标记。 我的操作系统是LinuxLubuntu18.04,我使用的是Python3.x。 只有EXIF标签可以通过各种方法进行更改。你知道吗

对于读取和写入EXIF标记,我可以使用例如:

  • 命令行工具:exiftool
  • python模块:exifrad
  • python模块:PIL
  • python模块:tifffile
  • python模块:skimage.external.tifffile文件你知道吗

尤其是python模块似乎对GeoTiff标记“视而不见”,即它们只读取(和写入)EXIF标记,而不读取GeoTiff标记。 使用exiftool,我至少可以读取和打印GeoTiff标签以及其他标签。 例如,通过exiftool对我的TIFF文件(也包括GeoTiff标记)的控制台输出是:

输入:

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标记“Projection”,它在不更改任何内容的情况下抛出以下警告消息: 输入:

exiftool "-Projection=" "newfile.tif"

输出:

Warning: Sorry, Projection is not writable. Nothing to do.

在我的互联网搜索中,我发现了其他的库和包,它们也许可以帮助我,但到目前为止没有任何帮助,因为我没有找到文档,或者它不起作用:

  • libtiff(通过命令tiffset,例如“tiffset-s Tag Number Tag Value dst file”,它只更改/添加EXIF标记,但不接触GeoTIFF标记)
  • 文库
  • gdal\ U编辑、gdal\ U翻译(或一般gdal)

至于后一种方法gdal_editgdal_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"

如您所见,在该示例中,我尝试将GeoTIFF标签号3075(名为“ProjCoordTrans”)修改为costum字符串。当执行这4个命令中的任何一个时,没有抛出任何错误,但随后通过检查TIFF标记

exiftool -D -G -a -u -U -f -s "newfile.tif"

我发现同样的标签仍然没有改变。你知道吗

我想知道是否有可能改变GeoTiff标签。一定有可能。你知道吗


Tags: 模块标记datetype标签fileexifproj
1条回答
网友
1楼 · 发布于 2024-03-29 07:09:20

我在exiftool本身的项目页面上发现了一个answer。 此后,我将在页面作者Phil Harvey的帮助下总结我发现的内容。你知道吗

要将所有GeoTiff标记从一个文件复制到另一个文件,请执行以下操作:

exiftool -tagsfromfile SRCFILE -GeoTiffDirectory -GeoTiffDoubleParams -GeoTiffAsciiParams DSTFILE

这就成功了。 我假设这些伪标记是由exiftools在所有子GeoTiff标记中分割的,因为python中的其他工具将这些伪标记及其相关编号打印出来。 Python包,能够显示这些通用的3个Geotiff标记

  • ('34735')'GeoKeyDirectoryTag'
  • ('34736')'GeoDoubleParamsTag'
  • ('34737')'geoaschiparamstag'

例如:

import PIL
import tifffile as tf
from skimage.external import tifffile as sk_tf

通过应用于示例TIFF的python脚本使用枕头(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|',)'
...

要单独更改投影标记,当前必须手动编辑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                                           [>.]

>;编辑中的字节0x56和0x57输出.dat要更改为所需的任何投影,请将修改后的GeoTiff目录放回TIFF文件中:

exiftool "-geotiffdirectory<=out.dat" FILE.tif

然而,需要注意的是,更改3个GeoTIFF标记,而不是试图通过修改上述二进制文件并将其重新分配给所讨论的TIFF来操作单个GeoTIFF标记中的一个,可能更有效。你知道吗

为了完成,这3个GeoTIFF标签是:

  • ('34735')'GeoKeyDirectoryTag'
  • ('34736')'GeoDoubleParamsTag'
  • ('34737')'geoaschiparamstag'

尽管如此,只要在二进制文件中更改一个特定的GeoTIFF标记,就有可能更新新TIFF中3个关键的GeoTIFF摘要标记。 我还没试过呢。你知道吗

如果您必须添加一些额外的信息或经验,这些方法,为您工作等,让我知道。你知道吗

干杯

相关问题 更多 >