Skip to main content
johnrellis
Legend
Feb 20, 2019 8:40 PM UTC
Released

P: Loses precision in exported EXIF GPS coordinates

[This is fixed in LR 8.3 -- John Ellis]

LR unnecessarily reduces the precision in exported EXIF GPS coordinates to about 18 centimeters.  A trivial one-line fix would increase the precision of exported coordinates to about 0.004 centimeters.


ModernGPS augmentation systems and post-processing can produce coordinates with accuracy at the centimeter level or finer.   For example, this LR user is processingdrone pics for photogrammetry applications: https://forums.adobe.com/message/10936939

Thisbug affects coordinates in exported JPEGs and TIFFs but not in raw XMPsidecars, which maintain high precision.

Workaround

Aworkaround is to use the Run Any Command plugin to create an exportpost-process action that runs ExifTool with arguments that copy the GPScoordinates from the original to the exported file.

Details of the Bug

EXIFrepresents GPS coordinates with three rationals (fractions) for degrees,minutes, and seconds. The numerators and denominators are stored as 32-bitunsigned integers, allowing extremely fine precision (on the order of 1 part in70 million of latitude or longitude seconds).

Forexample, ExifTool stores the latitude 37.1234567891389 in EXIF with these threerationals:

degrees= 37 / 1
minutes= 7 / 1
seconds= 767091 / 31381

LRstores GPS coordinates in the catalog as 64-bit floating point numbers, whichallow 15 decimal digits of precision, with at least 12 fractional digits. Thisprovides a precision of roughly 0.00001 (10^-5) centimeters.

Butinexplicably, LR exports EXIF coordinates using a minutes denominator of only10,000, limiting precision to about 18 centimeters. For example, it exportslatitude 37.1234567891389 as:

degrees= 37 / 1
minutes = 74074 /10000
seconds= 0 / 1

(Youcan examine the rational representation of the exported coordinates using"exiftool -v".)

Thefix is trivial -- use a minutes denominator of 50,000,000 rather than 10,000,which will increase the precision to about 0.004 centimeters.  (A denominator of 50,000,000   is small enough to allow a maximum value of60 to be represented as a 32-bit unsigned rational.) 

Here'ssample code of how to do the conversion from floating point to the EXIFrational representation:

function degreesToEXIF (d)
    local sign = d >= 0 and 1 or -1
    local degrees, fracDegrees = math.modf (math.abs (d))
    local minutes = fracDegrees * 60
    local minutesDen = 50e6
    local minutesNum = math.floor (minutes * minutesDen + 0.5)
    if minutesNum == 60 * minutesDen then
        degrees, minutesNum = degrees + 1, 0
        end
    return sign, degrees, 1, minutesNum, minutesDen, 0, 1
    end
This topic is closed to new replies. Start a new post to keep the conversation going.

21 replies

johnrellis
Legend
Mar 11, 2019 11:22 PM UTC
Glad it's working

"LR was strangely converting 784.96151731720727 meters to 500 meters"

That is curious.  With the test photo you posted above, my LR preserved on export its altitude of  784.9615173 m.

Can you reproduce that problem with other photos?


Translate
Participating Frequently
Mar 11, 2019 9:43 PM UTC
Thanks John, that works perfectly. I also added the -gpsaltitude for the altitude
since LR was strangely converting 784.96151731720727 meters to 500 meters:

"C:\Windows\exiftool.exe" -tagsfromfile "{FullMasterFile}" -gpsaltitude -gpslatitude -gpslongitude "{FullExportedFile}"




Translate
johnrellis
Legend
Mar 8, 2019 6:34 AM UTC
I was mistaken -- the coordinates stored in the catalog don't match those stored in the file's EXIF.  They're considerably less precise.

For example, if EXIF:GPSLatitude = 46/1 39/1 44037/2000 = 46.65611625, the catalog stores 
46.656116666667, a difference of 4.16667E-7, about 5 cm.

I'm wondering if LR's EXIF reader is improperly using 32-bit floats rather than 64-bit floats to read the GPS coordinates.  Hmm...

Regardless, this Run Any Command command line will copy the coordinates directly from the master file into the exported file, preserving all the precision of the master and ignoring what LR has stored in its catalog:
/usr/local/bin/exiftool -tagsfromfile "{FullMasterFile}" -gpslatitude -gpslongitude "{FullExportedFile}"
Note that this only works with masters that are JPEGs and TIFFs, not raws (which may have .xmp sidecars storing their metadata).  To handle raws with sidecars would take a little extra scripting.
Translate
Participating Frequently
Mar 8, 2019 3:23 AM UTC
Here is one of the geotagged images: https://photos.app.goo.gl/sy9Xxm6sBFdpL4rb9
Thanks

Translate
johnrellis
Legend
Mar 8, 2019 3:07 AM UTC
There shouldn't be any difference between Mac and Windows. Why don't you upload a sample photo to Dropbox or similar and post the sharing link here.  That will let me see what might be going wrong.
Translate
Participating Frequently
Mar 7, 2019 10:59 PM UTC
Thanks John for the instructions, but I am still having troubles.  I got the Run any Command script working and ExifTools command  working, but it appears that when the Run any Command/ExifTool fetches the original Lat/Long/Alt coordinates for the image, it's only getting the converted LR coordinates instead of the actual coordinates.  Were you able to get the original coordinates using a Mac? I am using Windows. Could this be my problem?

Thanks in advance.
Translate
johnrellis
Legend
Mar 6, 2019 6:33 AM UTC
Here's how to configure Run Any Command on Mac to copy the high-precision GPS coordinates from the catalog to the exported file:



The "Command per image" is:
/usr/local/bin/exiftool -gpslatitude={Latitude} -gpslongitude={Longitude} "{FullExportedFile}"
Note you'll have to install the free ExifTool also.

The Windows command line is similar -- just use the full path to "exiftool.exe" at the beginning of the command line.


Translate
johnrellis
Legend
Mar 4, 2019 11:47 PM UTC
I'm jammed today but will try to get to this tomorrow.
Translate
Participating Frequently
Mar 4, 2019 11:17 PM UTC
Hi John, I am trying to do the workaround but I can't seem to get it to work. I have installed the exiftools and the Run any command plugin. Do use the Command per Image or the Command to execute upon completion of all images? What would the command be? 
I would be grateful for any help.

Translate
johnrellis
Legend
Feb 21, 2019 4:51 PM UTC
Thanks.
Translate