예제 #1
0
def project(
        bbox: s2.LatLngRect, size: XY, offset: XY,
        latlnglines: List[List[s2.LatLng]]) -> List[List[Tuple[float, float]]]:
    min_x = lng2x(bbox.lng_lo().degrees)
    d_x = lng2x(bbox.lng_hi().degrees) - min_x
    while d_x >= 2:
        d_x -= 2
    while d_x < 0:
        d_x += 2
    min_y = lat2y(bbox.lat_lo().degrees)
    max_y = lat2y(bbox.lat_hi().degrees)
    d_y = abs(max_y - min_y)

    scale = size.x / d_x if size.x / size.y <= d_x / d_y else size.y / d_y
    offset = offset + 0.5 * (size - scale * XY(d_x, -d_y)) - scale * XY(
        min_x, min_y)
    lines = []
    for latlngline in latlnglines:
        line = []
        for latlng in latlngline:
            if bbox.contains(latlng):
                line.append((offset + scale * latlng2xy(latlng)).tuple())
            else:
                if len(line) > 0:
                    lines.append(line)
                    line = []
        if len(line) > 0:
            lines.append(line)
    return lines
예제 #2
0
 def select_relevant_states(
         self, view: s2sphere.LatLngRect, t0: datetime.datetime,
         t1: datetime.datetime) -> List[rid.RIDAircraftState]:
     recent_states: List[rid.RIDAircraftState] = []
     previously_outside = False
     previously_inside = False
     previous_telemetry = None
     for telemetry in self.telemetry:
         if (telemetry.timestamp.datetime < t0
                 or telemetry.timestamp.datetime > t1):
             # Telemetry not relevant based on time
             continue
         pt = s2sphere.LatLng.from_degrees(telemetry.position.lat,
                                           telemetry.position.lng)
         inside_now = view.contains(pt)
         if inside_now:
             if previously_outside:
                 recent_states.append(previous_telemetry)
             recent_states.append(telemetry)
             previously_inside = True
             previously_outside = False
         else:
             if previously_inside:
                 recent_states.append(telemetry)
             previously_outside = True
             previously_inside = False
         previous_telemetry = telemetry
     return recent_states