Copying GEOTIFF tags

Started by yvecai, June 13, 2010, 12:09:59 PM

Previous topic - Next topic

yvecai

I am modifying GeoTIFF images with ImageMagick, which does not keep all tags from the original image.
Then I would like to copy all the tags from original image to the one created by ImageMagick. Maybe this is not so simple because it doesn't work with -tagsfromfiles old.tiff -ALL:ALL new.tiff.

Here is a tag set from the orginal image:
yves@maisonuxII:~/mapnik/SRTM/data/TIF$ exiftool -G -D hillshade.tif
[ExifTool]          - ExifTool Version Number         : 7.89
[File]              - File Name                       : hillshade.tif
[File]              - Directory                       : .
[File]              - File Size                       : 281 MB
[File]              - File Modification Date/Time     : 2010:05:13 10:43:09+02:00
[File]              - File Type                       : TIFF
[File]              - MIME Type                       : image/tiff
[File]              - Exif Byte Order                 : Little-endian (Intel, II)
[EXIF]            256 Image Width                     : 18554
[EXIF]            257 Image Height                    : 15887
[EXIF]            258 Bits Per Sample                 : 8
[EXIF]            259 Compression                     : Uncompressed
[EXIF]            262 Photometric Interpretation      : BlackIsZero
[EXIF]            273 Strip Offsets                   : (Binary data 152905 bytes, use -b option to extract)
[EXIF]            277 Samples Per Pixel               : 1
[EXIF]            278 Rows Per Strip                  : 1
[EXIF]            279 Strip Byte Counts               : (Binary data 95321 bytes, use -b option to extract)
[EXIF]            284 Planar Configuration            : Chunky
[EXIF]            339 Sample Format                   : Unsigned integer
[EXIF]          33550 Pixel Scale                     : 30 30 0
[EXIF]          33922 Model Tie Point                 : 0 0 0 333958.472379821 5942074.07243111 0
[EXIF]          42113 GDAL No Data                    : 0
[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                     : unnamed
[GeoTiff]        2048 Geographic Type                 : User Defined
[GeoTiff]        2049 Geog Citation                   : unnamed ellipse
[GeoTiff]        2050 Geog Geodetic Datum             : User Defined
[GeoTiff]        2054 Geog Angular Units              : Angular Degree
[GeoTiff]        2056 Geog Ellipsoid                  : User Defined
[GeoTiff]        2057 Geog Semi Major Axis            : 6378137
[GeoTiff]        2058 Geog Semi Minor Axis            : 6378137
[GeoTiff]        3072 Projected CS Type               : User Defined
[GeoTiff]        3074 Projection                      : User Defined
[GeoTiff]        3075 Proj Coord Trans                : Mercator
[GeoTiff]        3076 Proj Linear Units               : Linear Meter
[GeoTiff]        3080 Proj Nat Origin Long            : 0
[GeoTiff]        3081 Proj Nat Origin Lat             : 0
[GeoTiff]        3082 Proj False Easting              : 0
[GeoTiff]        3083 Proj False Northing             : 0
[GeoTiff]        3092 Proj Scale At Nat Origin        : 1
[Composite]         - Image Size                      : 18554x15887


And here from image created by IM:

[ExifTool]          - ExifTool Version Number         : 7.89
[File]              - File Name                       : hillshade_NBC.tif
[File]              - Directory                       : .
[File]              - File Size                       : 281 MB
[File]              - File Modification Date/Time     : 2010:06:13 18:02:47+02:00
[File]              - File Type                       : TIFF
[File]              - MIME Type                       : image/tiff
[File]              - Exif Byte Order                 : Little-endian (Intel, II)
[EXIF]            256 Image Width                     : 18554
[EXIF]            257 Image Height                    : 15887
[EXIF]            258 Bits Per Sample                 : 8
[EXIF]            259 Compression                     : Uncompressed
[EXIF]            262 Photometric Interpretation      : BlackIsZero
[EXIF]            266 Fill Order                      : Normal
[EXIF]            269 Document Name                   : hillshade_NBC.tif
[EXIF]            273 Strip Offsets                   : (Binary data 152876 bytes, use -b option to extract)
[EXIF]            274 Orientation                     : Horizontal (normal)
[EXIF]            277 Samples Per Pixel               : 1
[EXIF]            278 Rows Per Strip                  : 1
[EXIF]            279 Strip Byte Counts               : (Binary data 95321 bytes, use -b option to extract)
[EXIF]            282 X Resolution                    : 72
[EXIF]            283 Y Resolution                    : 72
[EXIF]            284 Planar Configuration            : Chunky
[EXIF]            296 Resolution Unit                 : inches
[EXIF]            297 Page Number                     : 0 1
[EXIF]            305 Software                        : ImageMagick 6.5.7-8 2009-11-26 Q16 http://www.imagemagick.org
[Composite]         - Image Size                      : 18554x15887


Phil Harvey

Sorry, ExifTool does not yet have the ability to write GeoTiff tags.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

yvecai

That's a fast and precise answer, thanks !

Looking a little more deeply how GeoTiffs are made to see how I could do, I've found geotifcp:
http://www.remotesensing.org/geotiff/geotifcp.html
Works perfectly.

All info on geotiff can be found here: http://trac.osgeo.org/geotiff/

mmx64

Quote from: Phil Harvey on June 13, 2010, 03:38:04 PM
Sorry, ExifTool does not yet have the ability to write GeoTiff tags.

Can I ask you what your plans are regarding writing/deleting GeoTiff tags?

Phil Harvey

I've had no requests yet to add this ability, so I haven't got any plans at this point.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mmx64

Well, conside this a humble request then ;) Especially removing the tag (for privacy issues).

Great program btw! Keep up the good work!

Phil Harvey

OK.  I'll put this on the list.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

I just took a quick look at this.  Now I remember why this ability wasn't added:

The GeoTIFF specification sucks.  Why can't people ever design a specification that is compatible with existing standards?  The unfortunate structure of the design means that it can't be processed in a single pass.  There is already special logic needed in ExifTool to cache the necessary GeoTIFF information in memory until it can be decoded, and writing it will be even more complicated. :(

But I will see what I can do.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mmx64

Well that sure sounds like it sucks :(
Anything you can do would be appreciated. Good luck!

caller82

hi,

has this feature been integrated so far? I am searching for a cross plattform solution to restore geotiff meta data after image magic removed it. geotifcp works fine, but only on linux. its hard to find a distributeable solution for windows, and even harder on mac :-(

please let me know if you have any alternative suggestions for me!

THX
-marco

Phil Harvey

#10
Hi Marco,

I should have realized this before, a simple copy of existing GeoTiff tags may be done by creating user-defined tags with the following config file:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Exif::Main' => {
        0x87af => {
            Name => 'GeoTiffDirectoryBlock',
            Format => 'undef',
            Writable => 'undef',
            Binary => 1,
        },
        0x87b0 => {
            Name => 'GeoTiffDoubleBlock',
            Format => 'undef',
            Writable => 'undef',
            Binary => 1,
        },
        0x87b1 => {
            Name => 'GeoTiffAsciiBlock',
            Writable => 'string',
            Binary => 1,
        },
    },
);


(see the sample config file for instructions on using a config file.)

The command is then:

exiftool -tagsfromfile src.tiff "-geotiff*" dst.tiff

This should work as long as the source and destination TIFF images have the same byte ordering.

- Phil

Edit:  I will build this ability into ExifTool 9.50, which will also properly handle the byte ordering.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

AndyLuckert

Dear community and author Phil Harvey,

I'm using Linux Lubuntu 18.04 with exiftool command line in order to modify TIFF-Tags of a land cover classification GeoTIFF-file.

As the Python libraries

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

don't even list the GeoTiff tags, as they are "blind on that eye", I found that exiftool lists, but cannot change them.


The output of my example file, using exiftool in the terminal, is:

Input:
exiftool -D -G -a -u -U -f "newfile.tif"
Output:
[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


Now, I'd like to change/delete the GeoTiff-TAG "Projection", which throws the following warning message without changing anything:
Input:
exiftool "-Projection=" "newfile.tif"
Output:
Warning: Sorry, Projection is not writable. Nothing to do.

Next, I found the following documentation of this very webpage:
https://exiftool.org/TagNames/GeoTiff.html

It states, among other details, the following:
QuoteGeoTIFF tags are not writable individually, but they may be copied en mass via the block tags GeoTiffDirectory, GeoTiffDoubleParams and GeoTiffAsciiParams.

Is there any possibility to change/rename/delete a GeoTiff-TAG of choice via command line exiftools as stated above in my attempt?
I'm quite desparate already, since I've invested a lot of time in finding a possiblity, but so far no avail.

Thanks in advance for helping me out.
Kind regards,
Andreas

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).