gh-31 Add test to check for conversion from decimal to degrees, minutes, seconds
This commit is contained in:
parent
853de0548a
commit
c4e817bde8
|
@ -54,10 +54,12 @@ def decimal_to_dms(decimal):
|
||||||
>>> decimal_to_dms(-125.976893)
|
>>> decimal_to_dms(-125.976893)
|
||||||
[Fraction(125, 1), Fraction(58, 1), Fraction(92037, 2500)]
|
[Fraction(125, 1), Fraction(58, 1), Fraction(92037, 2500)]
|
||||||
"""
|
"""
|
||||||
remainder, degrees = math.modf(abs(decimal))
|
|
||||||
remainder, minutes = math.modf(remainder * 60)
|
|
||||||
# @TODO figure out a better and more proper way to do seconds
|
# @TODO figure out a better and more proper way to do seconds
|
||||||
return (pyexiv2.Rational(degrees, 1), pyexiv2.Rational(minutes, 1), pyexiv2.Rational(int(remainder*1000000000), 1000000000))
|
degrees = int(decimal)
|
||||||
|
subminutes = abs((decimal - int(decimal)) * 60)
|
||||||
|
minutes = int(subminutes)
|
||||||
|
subseconds = abs((subminutes - int(subminutes)) * 60)
|
||||||
|
return (pyexiv2.Rational(degrees, 1), pyexiv2.Rational(minutes, 1), pyexiv2.Rational(subseconds, 1))
|
||||||
|
|
||||||
def dms_to_decimal(degrees, minutes, seconds, sign=' '):
|
def dms_to_decimal(degrees, minutes, seconds, sign=' '):
|
||||||
"""Convert degrees, minutes, seconds into decimal degrees.
|
"""Convert degrees, minutes, seconds into decimal degrees.
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Project imports
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||||
|
|
||||||
|
import helper
|
||||||
|
from elodie import geolocation
|
||||||
|
|
||||||
|
os.environ['TZ'] = 'GMT'
|
||||||
|
|
||||||
|
def test_decimal_to_dms():
|
||||||
|
target_decimal_value = 37.383336725
|
||||||
|
|
||||||
|
dms = geolocation.decimal_to_dms(target_decimal_value)
|
||||||
|
check_value = dms[0].to_float() + dms[1].to_float() / 60 + dms[2].to_float() / 3600
|
||||||
|
|
||||||
|
assert target_decimal_value == check_value, '%s does not match %s' % (check_value, target_decimal_value)
|
Loading…
Reference in New Issue