ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: adelpit on June 27, 2019, 04:06:00 PM

Title: GPSAltitude rational64s not preserved during copy tagsFromFile
Post by: adelpit on June 27, 2019, 04:06:00 PM
Hello,

I am trying to copy exif data from a jpg to a tiff.  Everything is mostly working, however I am having issues with the `GPSAltitude`.  It appears the official spec is to encode as a `rational64u`, however, DJI is often writing them as a `rational64s`.  This seems to work ok and exiftool and many other tools seem to handle it ok.  But when I go to copy to this field to the tiff, it gets converted to a `rational64u` and any sign is lost.  If the original value was negative, I would expect this to cause the `GPSAltitudeRef` bit to get flipped during copy to preserve the sign.

Here is my command for copying exif data to the tiff

exiftool -tagsFromFile  source.jpg -all:all -overwrite_original -r destination.tiff

Then checking the gpsaltitude fields:

exiftool -n -gpsaltitude* source.jpg destination.tiff
======== source.jpg
GPS Altitude Ref                : 0
GPS Altitude                    : -133.859
======== destination.tiff
GPS Altitude Ref                : 0
GPS Altitude                    : 133.859
    2 image files read


I can work around this by manually setting the GPSAltitudeRef value to preserve the original sign but I would like to find a cleaner solution.  Given that the GPSAltitude is not a `rational64u` as per the spec, I'm not sure if this is really an exiftool issue.  How do you advise properly handling negative `GPSAltitude` values when copying via tagsFromFile?  The source and destination images are attached. 

Thank you


Title: Re: GPSAltitude rational64s not preserved during copy tagsFromFile
Post by: Phil Harvey on June 27, 2019, 04:23:09 PM
Try this:

exiftool -tagsFromFile  source.jpg -all:all "-gpsaltituderef<gpsaltitude" -overwrite_original -r destination.tiff

The the Notes for the GPSAltitudeRef tag in the GPS tags documentation (https://exiftool.org/TagNames/GPS.html) to see why this works.

- Pil
Title: Re: GPSAltitude rational64s not preserved during copy tagsFromFile
Post by: adelpit on June 27, 2019, 04:43:42 PM
Thanks for the quick response.  That is exactly my current workaround.  That works when GPSAltitude<0 and GPSAltitudeRef=0.  However, I was thinking that would fail if the GPSAltitude<0 AND GPSAltitudeRef=1.  In this case, I would think it should set GPSAltitudeRef to 0 instead of 1.
Title: Re: GPSAltitude rational64s not preserved during copy tagsFromFile
Post by: Phil Harvey on June 27, 2019, 05:18:07 PM
Ah.  I see.  If the original GPSAltitude is positive then GPSAltitudeRef doesn't get written (it currently requires a leading "+").  OK, try this then:

exiftool -tagsFromFile  source.jpg -all:all -gpsaltituderef=above "-gpsaltituderef<gpsaltitude" -overwrite_original -r destination.tiff

I should maybe change it so writing with any non-negative number sets it to "Above Sea Level".

- Phil
Title: Re: GPSAltitude rational64s not preserved during copy tagsFromFile
Post by: adelpit on June 28, 2019, 02:28:53 PM
Great! Thank you very much for the help, Phil.

- Andrew