【问题标题】:How to convert latitude and longitude in DMS format into decimal format (and vice versa)? [closed]如何将DMS格式的经纬度转换为十进制格式(反之亦然)? [关闭]
【发布时间】:2013-06-16 02:41:38
【问题描述】:

python 是否包含任何库可以将 DMS 格式的纬度和经度转换为十进制格式,反之亦然?

【问题讨论】:

  • 我怀疑标准库中有类似的东西......
  • 他没有询问标准库。这是他要的图书馆:pypi.python.org/pypi/LatLon/1.0.2
  • 这是一个有效的问题,并且有一个有效的答案

标签: python python-3.x latitude-longitude converters


【解决方案1】:
# -*- coding: latin-1 -*-

#example for : 0°25'30"S, 91°7'W

def conversion(old):
    direction = {'N':-1, 'S':1, 'E': -1, 'W':1}
    new = old.replace(u'°',' ').replace('\'',' ').replace('"',' ')
    new = new.split()
    new_dir = new.pop()
    new.extend([0,0,0])
    return (int(new[0])+int(new[1])/60.0+int(new[2])/3600.0) * direction[new_dir]

lat, lon = u'''0°25'30"S, 91°7'W'''.split(', ')
print conversion(lat), conversion(lon)
#Output:
0.425 91.1166666667

来自:Python - Batch convert GPS positions to Lat Lon decimals

另一方面:

def deg_to_dms(deg):
    d = int(deg)
    md = abs(deg - d) * 60
    m = int(md)
    sd = (md - m) * 60
    return [d, m, sd]

#output
>>> deg_to_dms(91.1166666667)
[91, 7, 1.199953203467885e-07]
>>> deg_to_dms(0.425)
[0, 25, 30.0]

来自:Lat Long to Minutes and Seconds?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    相关资源
    最近更新 更多