python修改gps定位_Python - 将GPS位置批量转换为经纬度小数

Hi I have a legacy db with some positional data. The fields are just text fields with strings like this 0°25'30"S, 91°7'W. Is there some way I can convert these to two floating point numbers for Decimal Latitude and Decimal Longitude?

EDIT:

So an example would be: 0°25'30"S, 91°7'W -> 0.425, 91.116667 where the original single field position yields two floats.

Any help much appreciated.

解决方案

This approach can deal with seconds and minutes being absent, and I think handles the compass directions correctly:

# -*- coding: latin-1 -*-

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值