admin管理员组文章数量:1122846
I have a text file I'm trying to process that contains 2 pieces of data, and put that into a kml file for use in google earth.
The text file has repeating lines that look like this:
302201300410005,$GPRMC,142003.800,V,4340.4448,N,07924.9643,W,0.00,187.31,060919,,,N,V*16
302201300410005,+CCI: 3022013,-32,99.9,32,412.3125,78,27,42,-68
The line with $GPRMC is the output of a GPS receiver, the line with +CCI is the output of a radio receiver with various parameters I'm trying to log. The intent is to generate a kml file with every lat/long point marked with the radio receiver data in the description of the point.
The primary issue I've run into is that I can't for the life of me get the kml file generated. I'm more or less following the simplekml tutorial using:
kml.save=('file.kml')
Now I've tried just a file name and using a full path but no file is generated. No error output either, not sure whats going on. I have used print(kml.kml()) and there is the expected output, not sure why the file isn't saving.
I'm not a programmer, i use python because it's (generally) easy for me to automate some of the more monotonous things.
Code:
#import LA_names
import os
import csv
import simplekml
ccilist = ("MNI","RSSI","BER","LA","Freq","C1","nLA","nC2","nRSSI")
latlong = False
data = False
desc = ''
fp=input('Enter file path: ')
check_fp = os.path.isfile(fp)
kml = simplekml.Kml(open=1)
single_point = kml.newpoint(name="World",coords=[(0.0,0.0)])
if check_fp == True:
with open(fp) as file_obj:
reader_obj = csv.reader(file_obj)
for row in reader_obj:
if '$GPRMC' in row:
latlong = False
lat = int(str(row[4])[:2])
lat_mm = float(str(row[4])[2:])
lat = lat + (lat_mm/60)
if row[5] == 'S':
lat = -abs(lat)
long = int(str(row[6])[:3])
long_mm = float(str(row[4])[2:])
long = long + (long_mm/60)
if row[7] == 'W':
long = -abs(long)
latlong = True
#print(f"LAT:{lat}\tLONG:{long}")
if '+CCI: 3022013' in row:
desc = f"RSSI:{row[2]}dBm\nLA:{row[4]}\nFreq:{row[5]}MHz\nC1:{row[6]}\nnLA:{row[7]}\nnC2:{row[8]}\nnRSSI:{row[9]}dBm"
data = True
if latlong == True and data == True:
pnt = kml.newpoint()
pnt.description = desc
pnt.coords = [(long, lat)]
pnt.shape = 'circle'
latlong = data = False
kml.save=('Test.kml')
#print (kml.kml())
else:
print ("File Not Found")
本文标签: Python amp simplekml module cannot save a fileStack Overflow
版权声明:本文标题:Python & simplekml module cannot save a file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301731a1931279.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论