在Python中将DD(十进制度数)转换为DMS(度数分钟秒)? [英] Convert DD (decimal degrees) to DMS (degrees minutes seconds) in Python?

查看:598
本文介绍了在Python中将DD(十进制度数)转换为DMS(度数分钟秒)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中将小数度转换为度分秒?已经编写了公式吗?

How do you convert Decimal Degrees to Degrees Minutes Seconds In Python? Is there a Formula already written?

推荐答案

这正是发明divmod的目的:

>>> def decdeg2dms(dd):
...   mnt,sec = divmod(dd*3600,60)
...   deg,mnt = divmod(mnt,60)
...   return deg,mnt,sec

>>> dd = 45 + 30.0/60 + 1.0/3600
>>> print dd
45.5002777778
>>> decdeg2dms(dd)
(45.0, 30.0, 1.0)

这篇关于在Python中将DD(十进制度数)转换为DMS(度数分钟秒)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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