exiftool implements wrong gps coordinates

Started by banana123, January 24, 2024, 06:48:12 AM

Previous topic - Next topic

banana123

Hi guys,
while trying to implement coordinated to the GPS tags (GPSLatitude,GPSLongitude) it seems like exiftool implements the wrong values.
For example:
input value = 56.56565656
implemented value = 56.5656565656556

It seems that from some length of the coordinate the exiftool shifts the number.

Does anybody know about that problem? Couldn't find it on the forum..

thanks!!

Phil Harvey

This is not a problem.  There is a limit on the precision possible with EXIF GPS coordinates.  What you are seeing is just rounding errors.  I think the precision is of the order millimetres.   But your numbers don't match up with what I see:

> exiftool a.jpg -gpslatitude=56.56565656
    1 image files updated
> exiftool a.jpg -gpslatitude#
GPS Latitude                    : 56.5656565600056

FYI:  Coordinates are stored as 3 rationals by the EXIF specification (degrees, minutes and seconds).  In this particular case, the rationals are 56/1, 33/1 and 251889/4469.

- 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 ($).

banana123

Quote from: Phil Harvey on January 24, 2024, 07:30:48 AMThis is not a problem.  There is a limit on the precision possible with EXIF GPS coordinates.  What you are seeing is just rounding errors.  I think the precision is of the order millimetres.   But your numbers don't match up with what I see:

> exiftool a.jpg -gpslatitude=56.56565656
    1 image files updated
> exiftool a.jpg -gpslatitude#
GPS Latitude                    : 56.5656565600056

FYI:  Coordinates are stored as 3 rationals by the EXIF specification (degrees, minutes and seconds).  In this particular case, the rationals are 56/1, 33/1 and 251889/4469.

- Phil


Yes you are right, i wrote the wrong implemented value - yours is the correct one, sorry.

So what will be the proper way to implement coordinates? limit the length of the coordinate?

Phil Harvey

Quote from: banana123 on January 24, 2024, 07:46:27 AMSo what will be the proper way to implement coordinates?

I don't understand.  Implement how?  Why isn't this already "proper"?

- 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 ($).

banana123

Quote from: Phil Harvey on January 24, 2024, 07:51:02 AM
Quote from: banana123 on January 24, 2024, 07:46:27 AMSo what will be the proper way to implement coordinates?

I don't understand.  Implement how?  Why isn't this already "proper"?

- Phil

Its not "proper" because i want the implemented value to match the given value exactly

Phil Harvey

Limit your precision to 10 decimal places (0.01 mm resolution):

> exiftool a.jpg -gpslatitude -c %.10f
GPS Latitude                    : 56.5656565600

- 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 ($).

banana123

#6
Quote from: Phil Harvey on January 24, 2024, 08:02:45 AMLimit your precision to 10 decimal places (0.01 mm resolution):

> exiftool a.jpg -gpslatitude -c %.10f
GPS Latitude                    : 56.5656565600

- Phil

I must use the full length.
Do you know what is the formula to convert a decimal coordinate to the value that is stored in EXIF?
That way i could confirm my value is stored correctly.

Thanks again Phil!

wywh

#7
It seems you can check the precision as fractions with the -v3 option. Here latitude and longitude written with 10 and 9 decimals:

exiftool -overwrite_original '-GPSLatitude*=0.0005555555' '-GPSLongitude*=0.000555555' image.jpg

exiftool -a -G1 -s -n -Location:All image.jpg
[GPS]           GPSLatitude                     : 0.0005555555
[GPS]           GPSLongitude                    : 0.000555555

exiftool -a -G1 -s -Location:All image.jpg
[GPS]           GPSLatitude                     : 0 deg 0' 2.00"
[GPS]           GPSLongitude                    : 0 deg 0' 2.00"

exiftool -a -G1 -s -v3 image.jpg
  | | 2)  GPSLatitude = 0 0 1.9999998 (0/1 0/1 9999999/5000000)
  | | 4)  GPSLongitude = 0 0 1.999998 (0/1 0/1 999999/500000)

18 decimals (about 1.11 * 10^-13 m precision...) seems to be the max my setup can input:

exiftool -overwrite_original '-GPSLatitude*=0.000123456790111111' '-GPSLongitude*=0.00012345679011111111' image.jpg

exiftool -a -G1 -s -n -Location:All image.jpg
[GPS]           GPSLatitude                     : 0.000123456790111111
[GPS]           GPSLongitude                    : 0.000123456790111111

exiftool -a -G1 -s -Location:All image.jpg
[GPS]           GPSLatitude                     : 0 deg 0' 0.44"
[GPS]           GPSLongitude                    : 0 deg 0' 0.44"

exiftool -a -G1 -s -v3 image.jpg
  | | 2)  GPSLatitude = 0 0 0.4444444444 (0/1 0/1 4/9)
  | | 4)  GPSLongitude = 0 0 0.4444444444 (0/1 0/1 4/9)

https://exiftool.org/forum/index.php?topic=15175.msg81595#msg81595

- Matti

Phil Harvey

Quote from: banana123 on January 25, 2024, 01:06:46 AMThat way i could confirm my value is stored correctly.

If you use ExifTool to write it, then it is stored correctly.  :)

- 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 ($).

StarGeek

Quote from: banana123 on January 25, 2024, 01:06:46 AMI must use the full length.
Do you know what is the formula to convert a decimal coordinate to the value that is stored in EXIF?
That way i could confirm my value is stored correctly.

As Phil says, exiftool is saving the values correctly.  There are always going to be rounding issues when converting fractions to decimal and back.  See Floating-point arithmetic.

But you can find the conversion routines in the GPS.pm file.  The routine to convert from decimal to degrees/minutes/seconds is on line 485 and to convert from degrees/minutes/seconds to decimal is on line 570.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Quote from: StarGeek on January 25, 2024, 11:34:54 AMBut you can find the conversion routines in the GPS.pm file.  The routine to convert from decimal to degrees/minutes/seconds is on line 485 and to convert from degrees/minutes/seconds to decimal is on line 570.

...and the routine to convert these values to rational64u is at Writer.pl line 5205, with the complicated rationalization done by Rationalize() at  Writer.pl line 5132.

(lots of work done behind the scenes)

- 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 ($).

wywh

Quote from: Phil Harvey on January 25, 2024, 11:50:53 AMlots of work done behind the scenes

Yes, I felt the Force when I wondered where those readily calculated GPS fractions came from  :)