In the spirit of this questions: Converting pandas data frame with degree minute second (DMS) coordinates to decimal degrees I want to convert a longitude with the format, for instance, 18-23-34W to a decimal, i.e., -18.392778. I want to separate by the minus, -, and by uppercase.
The function in the link I have been trying, adapted to my necessities:
def dms2dd(s):
degrees, minutes, seconds, direction = re.split('[A-Z-]+', s)
dd = float(degrees) + float(minutes) / 60 + float(seconds) / (60 * 60)
if direction in ('S', 'W'):
dd *= -1
return dd
The problem seems to be with the regex in degrees, minutes, seconds, direction = re.split('[A-Z-]+', s)
. I obtain the conversion but not the multiplication by -1, as it should be. Thx.