Add animation.

debian-sid
Tom Payne 16 years ago
parent a77d99e8ee
commit 090a8540c0

@ -1,4 +1,39 @@
from math import acos, atan2, cos, pi, sin, sqrt
R = 6371000.0
def _deg_to_rad(deg):
return pi * deg / 180.0
def _rad_to_deg(rad):
return 180.0 * rad / pi
class Coord:
def __init__(self, lat, lon, ele):
self.lat, self.lon, self.ele = lat, lon, ele
def distance_to(self, other):
"Return the distance from self to other."
lat1 = _deg_to_rad(self.lat)
lon1 = _deg_to_rad(self.lon)
lat2 = _deg_to_rad(other.lat)
lon2 = _deg_to_rad(other.lon)
d = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon1 - lon2)
return R * acos(d) if d < 1.0 else 0.0
def halfway_to(self, other):
"Return the point halfway between self and other."
lat1 = _deg_to_rad(self.lat)
lon1 = _deg_to_rad(self.lon)
ele1 = self.ele
lat2 = _deg_to_rad(other.lat)
lon2 = _deg_to_rad(other.lon)
ele2 = other.ele
bx = cos(lat2) * cos(lon1 - lon2)
by = cos(lat2) * sin(lon1 - lon2)
cos_lat1_plus_bx = cos(lat1) + bx
lat = _rad_to_deg(atan2(sin(lat1) + sin(lat2), sqrt(cos_lat1_plus_bx * cos_lat1_plus_bx + by * by)))
lon = _rad_to_deg(lon1 + atan2(by, cos_lat1_plus_bx))
ele = (ele1 + ele2) / 2.0
return Coord(lat, lon, ele)

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

@ -100,6 +100,7 @@ class dateTime:
class altitude(SimpleElement): pass
class altitudeMode(SimpleElement): pass
class begin(SimpleElement): pass
class color(SimpleElement): pass
@ -111,10 +112,12 @@ class coordinates(SimpleElement):
class description(SimpleElement): pass
class Document(CompoundElement): pass
class end(SimpleElement): pass
class extrude(SimpleElement): pass
class Folder(CompoundElement): pass
class href(SimpleElement): pass
class Icon(CompoundElement): pass
class IconStyle(CompoundElement): pass
class kml(CompoundElement):
@ -137,7 +140,9 @@ class name(SimpleElement): pass
class open(SimpleElement): pass
class overlayXY(SimpleElement): pass
class Placemark(CompoundElement): pass
class Point(CompoundElement): pass
class PolyStyle(CompoundElement): pass
class scale(SimpleElement): pass
class ScreenOverlay(CompoundElement): pass
class screenXY(SimpleElement): pass
class size(SimpleElement): pass
@ -152,6 +157,7 @@ class Style(CompoundElement):
class styleUrl(SimpleElement): pass
class TimeSpan(CompoundElement): pass
class visibility(SimpleElement): pass
class when(SimpleElement): pass
class width(SimpleElement): pass

@ -51,6 +51,9 @@ class Stock:
self.kmz.add_files({self.pixel_url: self.make_pixel()})
self.visible_none_folder = self.make_none_folder(1)
self.invisible_none_folder = self.make_none_folder(0)
animation_icon_url = 'images/paraglider.png'
self.animation_icon = kml.Icon(href=animation_icon_url)
self.kmz.add_files({animation_icon_url: open(animation_icon_url).read()})
class Hints:
@ -148,6 +151,24 @@ class Track:
folder.add(self.make_solid_track(hints, kml.Style(kml.LineStyle(color=hints.color, width=hints.width)), 'clampToGround', name='Solid color', visibility=0))
return folder
def make_animation(self, hints):
style = kml.Style(kml.IconStyle(hints.stock.animation_icon, color=hints.color, scale=0.5))
folder = kml.Folder(style, name='Animation', open=0, styleUrl=hints.stock.check_hide_children_style.url())
point = kml.Point(coordinates=[self.coords[0]], altitudeMode=hints.altitude_mode)
timespan = kml.TimeSpan(end=kml.dateTime(self.times[0]))
placemark = kml.Placemark(point, timespan, styleUrl=style.url())
folder.add(placemark)
for i in range(1, len(self.coords)):
point = kml.Point(coordinates=[self.coords[i - 1].halfway_to(self.coords[i])], altitudeMode=hints.altitude_mode)
timespan = kml.TimeSpan(begin=kml.dateTime(self.times[i - 1]), end=kml.dateTime(self.times[i]))
placemark = kml.Placemark(point, timespan, styleUrl=style.url())
folder.add(placemark)
point = kml.Point(coordinates=[self.coords[-1]], altitudeMode=hints.altitude_mode)
timespan = kml.TimeSpan(begin=kml.dateTime(self.times[-1]))
placemark = kml.Placemark(point, timespan, styleUrl=style.url())
folder.add(placemark)
return kmz.kmz(folder)
def kmz(self, hints):
folder = kmz.kmz(kml.Folder(name=self.meta.name, open=1))
rows = []
@ -170,6 +191,7 @@ class Track:
rows.append(('Landing altitude', '%dm' % self.coords[-1].ele))
folder.add(kml.description(kml.CDATA('<table>%s</table>' % ''.join(['<tr><th align="right">%s</th><td>%s</td></tr>' % row for row in rows]))))
folder.add(kml.Snippet(self.meta.pilot_name)) # FIXME
folder.add(self.make_animation(hints))
folder.add(self.make_track_folder(hints))
folder.add(self.make_shadow_folder(hints))
return folder

Loading…
Cancel
Save