Latitude / Longitud convertor: decimal <--> hex
## VERSION 1
# latitude / longitud convertor into decimal format
def latlon2dec(dlat,dlon):
"""
Example of input:
dlat = {'deg':34,'min':22,'sec':46}
dlon = {'deg':134,'min':43,'sec':45}
"""
latd = dlat['deg'] + (float(dlat['sec'])/60. + float(dlat['min'])) / 60.
lond = dlon['deg'] + (float(dlon['sec'])/60. + float(dlon['min'])) / 60.
return (latd,lond)
## VERSION 2
# hex to decimal
def dms2dd(degrees, minutes, seconds, direction):
dd = float(degrees) + float(minutes)/60 + float(seconds)/(60*60);
if direction == 'S' or direction == 'W':
dd *= -1
return dd;
# decimal to hex
def dd2dms(deg):
d = int(deg)
md = abs(deg - d) * 60
m = int(md)
sd = (md - m) * 60
return [d, m, sd]
# parse hex text ("36°57'9' N 110°4'21' W") to decimal
def parse_dms(dms):
import re
parts = re.split('[^\d\w]+', dms)
lat = dms2dd(parts[0], parts[1], parts[2], parts[3])
lng = dms2dd(parts[4], parts[5], parts[6], parts[7])
return (lat, lng)