【问题标题】:Unicode GPS Coordinates to Decimal ConversionUnicode GPS 坐标到十进制转换
【发布时间】:2017-08-11 11:38:11
【问题描述】:

问题

我在 python-2.7 中使用了一个代码,我得到了一个无用的 unicode 格式的 latlon 表达式(从调试器复制)

'latitude' = {unicode} u'N40°34\\'58.96"'
'longitude' = {unicode} u'W074°44\\'30.45"'

我想要这些作为浮动,即

'latitude' = {float} 40.583044
'longitude' = {float} -74.741792

我的尝试

我已将 unicode 转换为字符串,例如:

s = latitude.encode('utf-8')
t = longitude.encode('utf-8')
s = {str} 'N40°34\\'58.96"'
t = {str} 'W074°44\\'30.45"'

现在的问题是我需要在转换为正确的十进制表达式之前删除所有不需要的字符

【问题讨论】:

    标签: python-2.7 unicode gps


    【解决方案1】:

    这应该可行:

    import re
    def parseLonLat(l):
        l = re.split('[^\d\w\.]+', l)[:-1] # split into a list degree, minute, and second
        direction = l[0][0] # direction North, East, South or West
        l[0] = l[0][1:] # remove the character N or E or S or W
        return (1 if direction in ('N', 'E') else -1) * sum([float(n) / 60 ** i for i, n in enumerate(l)])
    

    【讨论】:

      猜你喜欢
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      相关资源
      最近更新 更多