How to convert degree minute second to degree decimal

后端 未结 6 2276
小鲜肉
小鲜肉 2021-02-07 13:37

I receive the latitude and longitude from GPS with this format:

Latitude : 78°55\'44.29458\"N

I need convert this data to:

latitude: 78.9288888889

<
6条回答
  •  旧时难觅i
    2021-02-07 14:04

    Here's my one liner (fine, fine – maybe it's two lines) :)

    import re
    lat = '''51°36'9.18"N'''
    deg, minutes, seconds, direction =  re.split('[°\'"]', lat)
    (float(deg) + float(minutes)/60 + float(seconds)/(60*60)) * (-1 if direction in ['W', 'S'] else 1)
    

    This outputs 51.60255

提交回复
热议问题