且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将度分秒转换为度十进制

更新时间:2023-02-11 09:02:07

问题是秒44.29458在.处被分开.

The problem is that the seconds 44.29458 are split at ..

您可以直接定义分割字符(而不是分割 not 的位置):

You could either define the split characters directly (instead of where not to split):

>>> re.split('[°\'"]+', """78°55'44.29458"N""")
['78', '55', '44.29458', 'N']

或保留正则表达式,然后合并第2部分和第3部分:

or leave the regular expression as it is and merge parts 2 and 3:

dms2dd(parts[0], parts[1], parts[2] + "." + parts[3], parts[4])


更新:

您的方法调用dd = parse_dms("78°55'44.33324"N )是语法错误.添加结尾的"并跳过另一个.或使用三引号引起来的字符串定义:

Your method call dd = parse_dms("78°55'44.33324"N ) is a syntax error. Add the closing " and escape the other one. Or use tripple quotes for the string definition:

parse_dms("""78°55'44.29458"N""")