如何将DMS格式的纬度和经度转换为十进制格式(反之亦然)? [英] How to convert latitude and longitude in DMS format into decimal format (and vice versa)?

查看:117
本文介绍了如何将DMS格式的纬度和经度转换为十进制格式(反之亦然)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Does python contain any library to convert latitude and longitude in DMS format into decimal format and vice versa?

推荐答案

# -*- 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-将GPS位置批量转换为Lat Lon小数点

以及另一种方式:

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]

来自:时间长到分钟和秒?

这篇关于如何将DMS格式的纬度和经度转换为十进制格式(反之亦然)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆