赞
踩
gps.txt
$GNGGA,032006.00,2930.35909,N,10634.37156,E,2,12,0.82,252.8,M,-26.5,M,,0000*66
$GNRMC,032007.00,A,2930.35909,N,10634.37156,E,0.000,250.87,190320,2.57,W,D*33
$GNGGA,032007.00,2930.35909,N,10634.37156,E,2,12,0.79,252.8,M,-26.5,M,,0000*63
$GNRMC,032008.00,A,2930.35910,N,10634.37156,E,0.016,250.86,190320,2.57,W,D*32
$GNGGA,032008.00,2930.35910,N,10634.37156,E,2,12,0.82,252.7,M,-26.5,M,,0000*6F
$GNRMC,032009.00,A,2930.35908,N,10634.37150,E,0.450,250.86,190320,2.57,W,D*3A
$GNGGA,032009.00,2930.35908,N,10634.37150,E,2,12,0.86,252.7,M,-26.5,M,,0000*65
$GNRMC,032010.00,A,2930.35904,N,10634.37132,E,0.809,250.76,190320,2.57,W,D*35
$GNGGA,032010.00,2930.35904,N,10634.37132,E,2,12,0.76,252.7,M,-26.5,M,,0000*6A
$GNRMC,032011.00,A,2930.35896,N,10634.37105,E,1.057,250.29,190320,2.57,W,D*32
程序运行环境:Python3.6
#!/usr/bin/env python # -*- coding: utf-8 -*- import re class GetGPS: def __init__(self, srcfile,dstfile): self.srcfile=srcfile; self.dstfile=dstfile; def run(self): print("GetGPS"+self.srcfile) print("run..."+'\n') print("SRC: "+self.srcfile+"\n") print("DST: " + self.dstfile + "\n") dstfd = open(self.dstfile, 'wt', encoding='UTF-8') if dstfd == None: return ; with open(self.srcfile, 'rt', encoding='UTF-8') as fd: for line in fd: line = line.strip('\n') #print(line); mtype=re.findall(r"\$(.+?),",line,re.M) #print(mtype[0]) if len(mtype) == 0 : continue if mtype[0]!="GNGGA": continue # print(line) #print(re.findall(r"[^ ]* [^,]*,[^,]*,(.+?),",line,re.M)) reg = re.compile(r'(?P<mtype>.+?),(?P<time_str>.+?),(?P<latitude_str>.+?),(?P<lathem_str>.+?),(?P<longtitude_str>.+?),(?P<longthem_str>.+?),[^,]*,[^,]*,[^,]*,(?P<altitude_str>.+?),(?P<altunit_str>.+?),') regMatch = reg.match(line) if regMatch == None : print(line) print("ERROR : regMatch == None") continue linebits = regMatch.groupdict() #for k, v in linebits.items(): # print(k + ": " + v) latitude=self.str2latitude(linebits["latitude_str"]) longtitude=self.str2longtitude(linebits["longtitude_str"]) strtmp=linebits["time_str"]+','+str(latitude)+','+linebits["lathem_str"]+','+str(longtitude)+','+linebits["longthem_str"]\ +','+linebits["altitude_str"]+','+linebits["altunit_str"] print(strtmp) dstfd.write(strtmp+'\n') fd.close(); dstfd.close(); def str2latitude(self,latitude_str): #print(latitude_str) degree=latitude_str[0:2] minute=latitude_str[2:] #print(degree+" "+minute) latitude=round(float(degree) + (float(minute) / 60),6) # print(latitude) return latitude def str2longtitude(self,longtitude_str): # print(longtitude_str) degree = longtitude_str[0:3] minute = longtitude_str[3:] # print(degree+" "+minute) longtitude = round(float(degree) + (float(minute) / 60),6) # print(longtitude) return longtitude
if __name__ == '__main__':
srcfile=r"d://gps.txt"
dstfile=r"d://gps_out.txt"
mobj=GetGPS(srcfile,dstfile);
mobj.run();
#gps_out.txt 数据格式为:世界时间,纬度,纬度半球,经度,经度半球,大地水准面高度异常差值,高度单位
032006.00,29.505985,N,106.572859,E,252.8,M
032007.00,29.505985,N,106.572859,E,252.8,M
032008.00,29.505985,N,106.572859,E,252.7,M
032009.00,29.505985,N,106.572858,E,252.7,M
032010.00,29.505984,N,106.572855,E,252.7,M
【文件】–> 【打开】–>选择gps_out.txt
【已限定】–>【逗号】–>【下一步】
【维度字段】选择第二项
【经度字段】选择第四项
注意:字段要与gps_out.txt数据格式相对应
可采用默认选项
在Google Earth软件的左侧位置管理窗口中选择临时位置里刚加入的gps_out.txt
可选择【否】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。