-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdateWaypointsFromKML.py
68 lines (49 loc) · 1.33 KB
/
updateWaypointsFromKML.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sqlite3
import sys
import xml.etree.ElementTree as ET
#Defult is triangel outside MSC
if len(sys.argv) > 1:
filepath = str(sys.argv[1])
else:
filepath = 'MSC.kml'
id = 0
is_checkpoint = 0
declination = 6
radius = 16
stay_time = 0
harvested = 0
wps = []
id = 0
#Steps trought tree to find all placemarks
def iterTree(element):
for child in element:
#print(child.tag)
if "Point" in child.tag:
wps.append(parsePoint(child))
iterTree(child)
#Gets coords and name from placemark
def parsePoint(point):
global id
id += 1
lat = ""
long = ""
for child in point:
if "coordinates" in child.tag:
cord = child.text
lat = cord.split()[0].split(',')[1]
long = cord.split()[0].split(',')[0]
return (id, is_checkpoint, lat,long, declination, radius, stay_time, harvested)
def main():
tree = ET.parse(filepath)
root = tree.getroot()
conn = sqlite3.connect('asr.db')
db = conn.cursor()
iterTree(root)
insertstr = "INSERT INTO currentMission (id, isCheckpoint, latitude, longitude, declination, radius, stay_time, harvested) VALUES "
db.execute('DELETE FROM currentMission')
for wp in wps:
print(insertstr+ str(wp))
db.execute(insertstr+ str(wp))
conn.commit()
db.close()
main()