From b686e7c2286d8ca885cfcb16b74efd37768ecc3d Mon Sep 17 00:00:00 2001 From: zserg Date: Fri, 12 Feb 2016 22:22:26 +0300 Subject: [PATCH] LatLon removed --- elodie/geolocation.py | 2 +- elodie/media/media.py | 5 +++++ elodie/media/photo.py | 32 ++++++-------------------------- elodie/tests/helper.py | 10 ++++++++++ elodie/tests/media/photo_test.py | 10 +++++----- requirements.txt | 1 - 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/elodie/geolocation.py b/elodie/geolocation.py index 75b003d..37d91e8 100644 --- a/elodie/geolocation.py +++ b/elodie/geolocation.py @@ -105,7 +105,7 @@ def decimal_to_dms(decimal, signed=True): def dms_to_decimal(degrees, minutes, seconds, direction=' '): sign = 1 - if(direction[0] in 'NEne'): + if(direction[0] in 'WSws'): sign = -1 return ( float(degrees) + float(minutes) / 60 + float(seconds) / 3600 diff --git a/elodie/media/media.py b/elodie/media/media.py index b98df36..209ea98 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -29,6 +29,11 @@ class Media(object): __name__ = 'Media' + d_coordinates = { + 'latitude' : 'latitude_ref', + 'longitude': 'longitude_ref' + } + def __init__(self, source=None): self.source = source self.exif_map = { diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 0dd20c1..2f59c63 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -6,7 +6,6 @@ image objects (JPG, DNG, etc.). """ import imghdr -import LatLon import os import pyexiv2 import re @@ -68,9 +67,7 @@ class Photo(Media): if(not self.is_valid()): return None - key = self.exif_map['latitude'] - if(type == 'longitude'): - key = self.exif_map['longitude'] + key = self.exif_map[type] exif = self.get_exif() if(key not in exif): @@ -79,29 +76,12 @@ class Photo(Media): try: # this is a hack to get the proper direction by negating the # values for S and W - latdir = 1 - if(type == 'latitude' and str(exif[self.exif_map['latitude_ref']].value) == 'S'): # noqa - latdir = -1 - - londir = 1 - if(type == 'longitude' and str(exif[self.exif_map['longitude_ref']].value) == 'W'): # noqa - londir = -1 - coords = exif[key].value - if(type == 'latitude'): - lat_val = LatLon.Latitude( - degree=coords[0], - minute=coords[1], - second=coords[2] - ) - return float(str(lat_val)) * latdir - else: - lon_val = LatLon.Longitude( - degree=coords[0], - minute=coords[1], - second=coords[2] - ) - return float(str(lon_val)) * londir + return geolocation.dms_to_decimal( + *coords, + direction = exif[self.exif_map[self.d_coordinates[type]]].value + ) + except KeyError: return None diff --git a/elodie/tests/helper.py b/elodie/tests/helper.py index 9959165..e54ce17 100644 --- a/elodie/tests/helper.py +++ b/elodie/tests/helper.py @@ -92,3 +92,13 @@ def time_convert(s_time): return time.gmtime((time.mktime(s_time))) else: return s_time + + +# isclose(a,b,rel_tol) +# To compare float coordinates a and b +# with relative tolerance c + +def isclose(a, b, rel_tol = 1e-8): + diff = abs(a - b) + return (diff <= abs(rel_tol * a) and + diff <= abs(rel_tol * b)) diff --git a/elodie/tests/media/photo_test.py b/elodie/tests/media/photo_test.py index 9ae5938..0f53e1d 100644 --- a/elodie/tests/media/photo_test.py +++ b/elodie/tests/media/photo_test.py @@ -57,31 +57,31 @@ def test_get_coordinate_default(): photo = Photo(helper.get_file('with-location.jpg')) coordinate = photo.get_coordinate() - assert coordinate == 37.3667027222, coordinate + assert helper.isclose(coordinate,37.3667027222), coordinate def test_get_coordinate_latitude(): photo = Photo(helper.get_file('with-location.jpg')) coordinate = photo.get_coordinate('latitude') - assert coordinate == 37.3667027222, coordinate + assert helper.isclose(coordinate,37.3667027222), coordinate def test_get_coordinate_latitude_minus(): photo = Photo(helper.get_file('with-location-inv.jpg')) coordinate = photo.get_coordinate('latitude') - assert coordinate == -37.3667027222, coordinate + assert helper.isclose(coordinate,-37.3667027222), coordinate def test_get_coordinate_longitude(): photo = Photo(helper.get_file('with-location.jpg')) coordinate = photo.get_coordinate('longitude') - assert coordinate == -122.033383611, coordinate + assert helper.isclose(coordinate,-122.033383611), coordinate def test_get_coordinate_longitude_plus(): photo = Photo(helper.get_file('with-location-inv.jpg')) coordinate = photo.get_coordinate('longitude') - assert coordinate == 122.033383611, coordinate + assert helper.isclose(coordinate,122.033383611), coordinate def test_get_coordinates_without_exif(): photo = Photo(helper.get_file('no-exif.jpg')) diff --git a/requirements.txt b/requirements.txt index cfb3339..3d208c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ click>=6.2,<7.0 -LatLon>=1.0.2,<2.0 requests>=2.9.1,<3.0 send2trash>=1.3.0,<2.0