Bug#4724; fixed processing of GPS Latitude/ Longitude with help from Helge.Privat...

svn: r16784
This commit is contained in:
Rob G. Healey 2011-03-09 04:00:07 +00:00
parent 6458f6c2a2
commit 786a0a5834

View File

@ -213,12 +213,14 @@ class MediaMetadata(Gramplet):
# Media image Artist
if KeyTag == ImageArtist:
self.exif_widgets["Artist"].set_text(_get_value(KeyTag, self.plugin_image)
self.exif_widgets["Artist"].set_text(
self._get_value(KeyTag)
)
# media image Copyright
elif KeyTag == ImageCopyright:
self.exif_widgets["Copyright"].set_text(_get_value(KeyTag, self.plugin_image)
self.exif_widgets["Copyright"].set_text(
self._get_value(KeyTag)
)
# media image DateTime
@ -226,7 +228,7 @@ class MediaMetadata(Gramplet):
# date1 may come from the image metadata
# date2 may come from the Gramps database
date1 = _get_value( KeyTag, self.plugin_image )
date1 = self._get_value(KeyTag)
date2 = active_media.get_date_object()
use_date = date1 or date2
@ -239,41 +241,45 @@ class MediaMetadata(Gramplet):
# Latitude and Latitude Reference
elif KeyTag == ImageLatitude:
latitude = _get_value(ImageLatitude, self.plugin_image)
longitude = _get_value(ImageLongitude, self.plugin_image)
latitude = self._get_value(ImageLatitude)
longitude = self._get_value(ImageLongitude)
# if latitude and longitude exist, display them...
if (latitude and longitude):
# split latitude metadata into (degrees, minutes, and seconds) from Rational
deg, min, sec = rational_to_dms(latitude)
latdeg, latmin, latsec = rational_to_dms(latitude, self.ValueType)
# Latitude Direction Reference
LatitudeRef = _get_value(ImageLatitudeRef, self.plugin_image)
self.exif_widgets["Latitude"].set_text(
"""%s° %s %s%s""" % (deg, min, sec, LatitudeRef)
)
# split longitude metadata into degrees, minutes, and seconds
deg, min, sec = rational_to_dms(longitude)
longdeg, longmin, longsec = rational_to_dms(longitude, self.ValueType)
# Longitude Direction Reference
LongitudeRef = _get_value(ImageLongitudeRef, self.plugin_image)
latfail = any(value == False for value in [latdeg, latmin, latsec])
longfail = any(value == False for value in [longdeg, longmin, longsec])
if not latfail and not longfail:
self.exif_widgets["Longitude"].set_text(
"""%s° %s %s%s""" % (deg, min, sec, LongitudeRef)
)
# Latitude Direction Reference
LatitudeRef = self._get_value(ImageLatitudeRef)
self.exif_widgets["Latitude"].set_text(
"""%s° %s %s%s""" % (latdeg, latmin, latsec, LatitudeRef)
)
# Longitude Direction Reference
LongitudeRef = self._get_value(ImageLongitudeRef)
self.exif_widgets["Longitude"].set_text(
"""%s° %s %s%s""" % (longdeg, longmin, longsec, LongitudeRef)
)
# Image Description Field
elif KeyTag == ImageDescription:
self.exif_widgets["Description"].set_text(
_get_value(ImageDescription, self.plugin_image)
self._get_value(ImageDescription)
)
# image Keywords
words = ""
keyWords = _get_value(IptcKeywords, self.plugin_image)
keyWords = self._get_value(IptcKeywords)
if keyWords:
index = 1
for word in keyWords:
@ -285,7 +291,7 @@ class MediaMetadata(Gramplet):
def make_row(self, pos, text, choices=None, readonly=False, callback_list=[],
mark_dirty=False, default=0, source=None):
import gtk
# Data Entry: Active Person
row = gtk.HBox()
label = gtk.Label()
@ -433,39 +439,49 @@ class MediaMetadata(Gramplet):
return rdate, rtime
def _get_value(self, KeyTag):
"""
gets the value from the Exif Key, and returns it...
@param: KeyTag -- image metadata key
@param: image -- pyexiv2 ImageMetadata instance
"""
self.ValueType = None
if "Exif" in KeyTag:
try:
KeyValue = self.plugin_image[KeyTag].value
self.ValueType = 0
except KeyError:
KeyValue = self.plugin_image[KeyTag].raw_value
self.ValueType = 1
except ValueError:
KeyValue = ""
except AttributeError:
KeyValue = ""
# Iptc KeyTag
elif "Iptc" in KeyTag:
try:
KeyValue = self.plugin_image[KeyTag].value
except KeyError:
KeyValue = "[not set]"
except ValueError:
KeyValue = ""
except AttributeError:
KeyValue = ""
return KeyValue
#------------------------------------------------
# Retrieve metadata from image
#------------------------------------------------
def _get_value(KeyTag, image):
"""
gets the value from the Exif Key, and returns it...
@param: KeyTag -- image metadata key
@param: image -- pyexiv2 ImageMetadata instance
"""
if "Exif" in KeyTag:
try:
KeyValue = image[KeyTag].value
except KeyError:
KeyValue = image[KeyTag].raw_value
except ValueError:
KeyValue = ""
# Iptc KeyTag
elif "Iptc" in KeyTag:
try:
KeyValue = image[KeyTag].value
except KeyError:
KeyValye = "[tag not set]"
except ValueError:
KeyValue = ""
return KeyValue
def convert_value(value):
"""
will take a value from the coordinates and return its value
@ -477,11 +493,33 @@ def convert_value(value):
value = (value.numerator / value.denominator)
return value
def rational_to_dms(coords):
def rational_to_dms(coords, ValueType):
"""
will return a rational set of coordinates to degrees, minutes, seconds
takes a rational set of coordinates and returns (degrees, minutes, seconds)
"""
return convert_value(coords[0]), convert_value(coords[1]), convert_value(coords[2])
deg, min, sec = False, False, False
if ValueType is not None:
if ValueType == 1:
deg, min, sec = coords.split(" ")
deg, rest = deg.split("/")
min, rest = min.split("/")
sec, rest = sec.split("/")
sec, rest = int(sec), int(rest)
if rest > 1:
sec = str( (sec/ rest) )
elif (ValueType == 0 and isinstance(coords, list) ):
if len(coords) == 3:
deg, min, sec = coords[0], coords[1], coords[2]
deg = convert_value(deg)
min = convert_value(min)
sec = convert_value(sec)
return deg, min, sec
#------------------------------------------------
# Support functions