Exif GPS lat/lng. Rational or list of 3 rationals?

Asked by Jim Easterbrook on 2012-10-16

As I understand it (from exiv2 documentation and other sources) GPS latitude and longitude should be written to EXIF as lists of three rationals: degrees, minutes and seconds. This is what I find in files produced by other software.

So far I've been unable to persuade pyexiv2 to write anything other than a single rational, using this sort of code:

new_tag = pyexiv2.ExifTag(key, fractions.Fraction(degrees).limit_denominator(1000000))

Any attempt to pass a list of three rationals to pyexiv2.ExifTag raises a ValueError: Invalid value exception.

Have I missed something in the documentation?


Question information

English Edit question
pyexiv2 Edit question
No assignee Edit question
Last query:
Last reply:
Olivier Tilloy (osomon) said : #1

pyexiv2 won’t accept a list of rationals for GPS coordinates. Instead, you should use the GPSCoordinate class that pyexiv2 provides. See http://tilloy.net/dev/pyexiv2/api.html#pyexiv2.utils.GPSCoordinate for detailed documentation.

I tried that before without success. Here's a simple test script:

import pyexiv2

coord = pyexiv2.utils.GPSCoordinate(51, 35, 25.678, 'N')
md = pyexiv2.ImageMetadata('')
md['Exif.GPSInfo.GPSLatitude'] = coord

When I run this I get an exception:

Traceback (most recent call last):
  File "code/photini/test_gps.py", line 7, in <module>
    md['Exif.GPSInfo.GPSLatitude'] = coord
  File "/usr/lib/python2.7/dist-packages/pyexiv2/metadata.py", line 271, in __setitem__
    return getattr(self, '_set_%s_tag' % family)(key, tag_or_value)
  File "/usr/lib/python2.7/dist-packages/pyexiv2/metadata.py", line 219, in _set_exif_tag
    tag = ExifTag(key, tag_or_value)
  File "/usr/lib/python2.7/dist-packages/pyexiv2/exif.py", line 107, in __init__
  File "/usr/lib/python2.7/dist-packages/pyexiv2/exif.py", line 197, in _set_value
    self.raw_value = self._convert_to_string(value)
  File "/usr/lib/python2.7/dist-packages/pyexiv2/exif.py", line 431, in _convert_to_string
    raise ExifValueError(value, self.type)
pyexiv2.exif.ExifValueError: Invalid value for EXIF type [Rational]: [51,35,25N]

Olivier Tilloy (osomon) said : #3

Indeed, I’m observing the same problem. It looks like a bug in pyexiv2. Could you please file a bug to track it? I believe the "Create bug report" link allows to directly file a bug from the question, and will link to it. Thanks.

Can you help with this problem?

Provide an answer of your own, or ask Jim Easterbrook for more information if necessary.

To post a message you must log in.