-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordinates_to_kml.py
More file actions
53 lines (48 loc) · 1.22 KB
/
coordinates_to_kml.py
File metadata and controls
53 lines (48 loc) · 1.22 KB
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
import sys
if len(sys.argv) != 3:
print("Usage: coordinates_to_kml.py <input_file> <output_file>")
exit()
input_file = open(sys.argv[1], "r")
output_file = open(sys.argv[2], "w")
coordinates = ""
last_coordinate = ""
for line in input_file:
last_coordinate = line.replace('\n', '') + ",0\n"
coordinates = coordinates + last_coordinate
output_file.write("""
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Path</name>
<Style id="yellowLineGreenPoly">
<LineStyle>
<color>7f00ffff</color>
<width>4</width>
</LineStyle>
<PolyStyle>
<color>7f00ff00</color>
</PolyStyle>
</Style>
<Placemark>
<name>File: {0}</name>
<styleUrl>#yellowLineGreenPoly</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<coordinates>
{1}
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>Current Location</name>
<Point>
<coordinates>
{2}
</coordinates>
</Point>
</Placemark>
</Document>
</kml>
""".format(sys.argv[1], coordinates, last_coordinate))