Google Earth導入GPS設備NMEA文本數據
一、提取GPS數據生成TXT文本文件
1 GPS設備NMEA文本數據
#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
2 GNGGA數據提取程序
程序運行環境:Python3.6
2.1 算法程序
#!/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
2.2 調用方法
if __name__ == '__main__':
srcfile=r"d://gps.txt"
dstfile=r"d://gps_out.txt"
mobj=GetGPS(srcfile,dstfile);
mobj.run();
2.3 提取GNGGA生成gps_out.txt文件
#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
二、 Google Earth導入TXT文本文件
1 啓動Google Earth
2 打開gps_out.txt
【文件】--> 【打開】-->選擇gps_out.txt
3 數據導入嚮導配置
3.1 指定分隔符
【已限定】-->【逗號】-->【下一步】
3.2 選擇維度/經度字段
【維度字段】選擇第二項
【經度字段】選擇第四項
注意:字段要與gps_out.txt數據格式相對應
3.3 指定字段類型
可採用默認選項
4 顯示GPS數據
4.1 配置Google Earth軟件的位置
在Google Earth軟件的左側位置管理窗口中選擇臨時位置裏剛加入的gps_out.txt
4.2 應用樣式模板
可選擇【否】
4.3 gps數據的展示效果