-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkml.py
62 lines (50 loc) · 1.9 KB
/
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
56
57
58
59
60
61
62
import os
import sys
import simplekml
from polycircles import polycircles
import time
import hashlib
M_IN_MILE = 1609.34
parent_folder = os.path.dirname(os.path.realpath(sys.argv[0])) + "/"
def points(points, filepath=None):
kml_obj = simplekml.Kml()
for p in points:
label = p[0]
point = p[1]
p = kml_obj.newpoint(
# name = label,
coords=[(point[1], point[0])])
# TODO: this is silly
hex_color = hashlib.md5(label).hexdigest()[6:14]
p.style.iconstyle.color = simplekml.Color.hex(hex_color)
if filepath is None:
filepath = str(time.time())
kml_obj.save(parent_folder + "output/" + filepath)
def save_kml(markers, filepath=None, extra_locations={}):
if filepath is None:
filepath = str(time.time())
kml_obj = simplekml.Kml()
for marker in markers:
centre_lat = marker.location[0]
centre_lon = marker.location[1]
outer_polycircle = polycircles.Polycircle(
latitude=centre_lat,
longitude=centre_lon,
radius=(marker.distance + (marker.precision / 2.0))*M_IN_MILE,
number_of_vertices=50)
inner_polycircle = polycircles.Polycircle(
latitude=centre_lat,
longitude=centre_lon,
radius=(marker.distance - (marker.precision / 2.0))*M_IN_MILE,
number_of_vertices=50)
pol = kml_obj.newpolygon(
name="%.6f, %.6f | %.3f" % (centre_lat, centre_lon, marker.distance),
outerboundaryis=outer_polycircle.to_kml(),
innerboundaryis=inner_polycircle.to_kml())
pol.style.polystyle.color = simplekml.Color.changealphaint(
100, simplekml.Color.red)
for key, loc in extra_locations.iteritems():
kml_obj.newpoint(
name=key,
coords=[(loc[1], loc[0])])
kml_obj.save(parent_folder + "output/" + filepath)