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

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

问题描述

如何在 Python 中将十进制度转换为度分秒?有没有已经写好的公式?

解决方案

这正是 divmod 的发明目的:

<预><代码>>>>def decdeg2dms(dd):... mnt,sec = divmod(dd*3600,60)... deg,mnt = divmod(mnt,60)... 返回 deg,mnt,sec>>>dd = 45 + 30.0/60 + 1.0/3600>>>打印 dd45.5002777778>>>decdeg2dms(dd)(45.0, 30.0, 1.0)

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

解决方案

This is exactly what divmod was invented for:

>>> 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天全站免登陆