def live_kml(cls, kml, timespan): users = User.objects.all() for user in users: period_logs = UasTelemetry.by_user(user)\ .filter(timestamp__gt=timezone.now() - timespan) if len(period_logs) < 1: continue linestring = kml.newlinestring(name=user.username) coords = [] for entry in period_logs: pos = entry.uas_position.gps_position # Spatial Coordinates coord = (pos.longitude, pos.latitude, units.feet_to_meters(entry.uas_position.altitude_msl)) coords.append(coord) linestring.coords = coords linestring.altitudemode = AltitudeMode.absolute linestring.extrude = 1 linestring.style.linestyle.color = Color.blue linestring.style.polystyle.color = Color.changealphaint( 100, Color.blue)
def live_kml(cls, kml, timespan): users = User.objects.all() for user in users: period_logs = UasTelemetry.by_user(user)\ .filter(timestamp__gt=timezone.now() - timespan) if len(period_logs) < 1: continue linestring = kml.newlinestring(name=user.username) coords = [] for entry in period_logs: pos = entry.uas_position.gps_position # Spatial Coordinates coord = (pos.longitude, pos.latitude, units.feet_to_meters(entry.uas_position.altitude_msl)) coords.append(coord) linestring.coords = coords linestring.altitudemode = AltitudeMode.absolute linestring.extrude = 1 linestring.style.linestyle.color = Color.blue linestring.style.polystyle.color = Color.changealphaint(100, Color.blue)
def kml(cls, user, logs, kml, kml_doc): """ Appends kml nodes describing the given user's flight as described by the log array given. Args: user: A Django User to get username from logs: A list of UasTelemetry elements kml: A simpleKML Container to which the flight data will be added kml_doc: The simpleKML Document to which schemas will be added Returns: None """ # KML Compliant Datetime Formatter kml_datetime_format = "%Y-%m-%dT%H:%M:%S.%fZ" icon = 'http://maps.google.com/mapfiles/kml/shapes/airports.png' threshold = 1 # Degrees kml_folder = kml.newfolder(name=user.username) flights = TakeoffOrLandingEvent.flights(user) if len(flights) == 0: return logs = filter(lambda log: cls._is_bad_position(log, threshold), logs) for i, flight in enumerate(flights): label = 'Flight {}'.format(i + 1) # Flights are one-indexed kml_flight = kml_folder.newfolder(name=label) flight_logs = filter(lambda x: flight.within(x.timestamp), logs) if len(flight_logs) < 2: continue coords = [] angles = [] when = [] for entry in flight_logs: pos = entry.uas_position.gps_position # Spatial Coordinates coord = (pos.longitude, pos.latitude, units.feet_to_meters(entry.uas_position.altitude_msl)) coords.append(coord) # Time Elements time = entry.timestamp.strftime(kml_datetime_format) when.append(time) # Degrees heading, tilt, and roll angle = (entry.uas_heading, 0.0, 0.0) angles.append(angle) # Create a new track in the folder trk = kml_flight.newgxtrack(name='Flight Path') trk.altitudemode = AltitudeMode.absolute # Append flight data trk.newwhen(when) trk.newgxcoord(coords) trk.newgxangle(angles) # Set styling trk.extrude = 1 # Extend path to ground trk.style.linestyle.width = 2 trk.style.linestyle.color = Color.blue trk.iconstyle.icon.href = icon for obstacle in MovingObstacle.objects.all(): obstacle.kml(path=flight_logs, kml=kml_flight, kml_doc=kml_doc)