Search code examples
gpsexif

GPSTrack from exif


How would I convert the rational64u GPSTrack --from an exif-- into a direction?

with:

import piexif
exif_dict = piexif.load('./img/IMG_1146.jpg')  
h = exif_dict['GPS'][piexif.GPSIFD.GPSTrack]  
h  

we get: (116001, 424)
with metapix the result is: GPSTrack 273.5872642. An example image here.

What must I do to (116001, 424) to get a bearing?


Solution

  • It is rational64u (as used in latitudes and longitudes, and in many places in EXIF) so a float is represented by two integers, a numerator and a denominator.

    To get the float, you just divide the two:

    degree = numerator / denominator 
    

    so

    degree = numerator / denominator = 116001 / 424 = 273.587264150943
    

    Usual warning: carious computer languages will do an integer division if the two operand are integer, so you may need to cast them to floats before doing the division.