-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlog_to_kml.py
executable file
·55 lines (48 loc) · 1.44 KB
/
log_to_kml.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
#!/usr/bin/env python
# Generate KML from a LOCUS log file
# KML template is based on the output from
# http://learn.adafruit.com/custom/ultimate-gps-parser
#
# usage: python kml.py > example.kml
# open the generated example.kml in Google Earth
#
# (c) 2013 Don Coleman
import locus
coords = locus.parseFile('sample.log')
# filter out any bad records
coords = [c for c in coords if c.fix > 0 and c.fix < 5]
# format each coordinate for kml
data = map(lambda c: "%3.14f,%3.14f,%s" % (c.longitude, c.latitude, c.height), coords)
template = """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>GPS Path</name>
<description>Path parsed from GPS data.</description>
<Style id="yellowLineGreenPoly">
<LineStyle>
<color>7f00ffff</color>
<width>4</width>
<gx:labelvisibility>0</gx:labelvisibility>
</LineStyle>
<PolyStyle>
<color>7f00ff00</color>
</PolyStyle>
</Style>
<Placemark>
<scale>0</scale>
<name>Begin</name>
<description>Start GPD Data</description>
<styleUrl>#yellowLineGreenPoly</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<coordinates>
%s
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
"""
print template % "\n".join(data)