Convert DD (decimal degrees) to DMS (degrees minutes seconds) in Python?

后端 未结 9 1962
花落未央
花落未央 2020-12-05 19:53

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

9条回答
  •  天命终不由人
    2020-12-05 20:03

    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)
    

提交回复
热议问题