Пример #1
0
def make_polygon(coords: List[Tuple[float, float]] = None,
                 latlngrect: s2sphere.LatLngRect = None) -> Dict:
    if coords is not None:
        return {
            "vertices": [{
                'lat': lat,
                'lng': lng
            } for (lat, lng) in coords]
        }

    return {
        "vertices": [
            {
                'lat': latlngrect.lat_lo().degrees,
                'lng': latlngrect.lng_lo().degrees
            },
            {
                'lat': latlngrect.lat_lo().degrees,
                'lng': latlngrect.lng_hi().degrees
            },
            {
                'lat': latlngrect.lat_hi().degrees,
                'lng': latlngrect.lng_hi().degrees
            },
            {
                'lat': latlngrect.lat_hi().degrees,
                'lng': latlngrect.lng_lo().degrees
            },
        ]
    }
Пример #2
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
Пример #3
0
def vertices_from_latlng_rect(rect: s2sphere.LatLngRect) -> List[Dict[str, float]]:
  return [
    {'lat': rect.lat_lo().degrees, 'lng': rect.lng_lo().degrees},
    {'lat': rect.lat_lo().degrees, 'lng': rect.lng_hi().degrees},
    {'lat': rect.lat_hi().degrees, 'lng': rect.lng_hi().degrees},
    {'lat': rect.lat_hi().degrees, 'lng': rect.lng_lo().degrees},
  ]
Пример #4
0
def make_polygon(coords: List[Tuple[float, float]] = None,
                 latlngrect: s2sphere.LatLngRect = None) -> Polygon:
    if coords is not None:
        return Polygon(
            vertices=[LatLngPoint(lat=lat, lng=lng) for (lat, lng) in coords])

    return Polygon(vertices=[
        LatLngPoint(lat=latlngrect.lat_lo().degrees,
                    lng=latlngrect.lng_lo().degrees),
        LatLngPoint(lat=latlngrect.lat_lo().degrees,
                    lng=latlngrect.lng_hi().degrees),
        LatLngPoint(lat=latlngrect.lat_hi().degrees,
                    lng=latlngrect.lng_hi().degrees),
        LatLngPoint(lat=latlngrect.lat_hi().degrees,
                    lng=latlngrect.lng_lo().degrees),
    ])
Пример #5
0
 def _determine_center(b: s2sphere.LatLngRect) -> s2sphere.LatLng:
     y1 = math.log((1 + math.sin(b.lat_lo().radians)) /
                   (1 - math.sin(b.lat_lo().radians))) / 2
     y2 = math.log((1 + math.sin(b.lat_hi().radians)) /
                   (1 - math.sin(b.lat_hi().radians))) / 2
     lat = math.atan(math.sinh((y1 + y2) / 2)) * 180 / math.pi
     lng = b.get_center().lng().degrees
     return s2sphere.LatLng.from_degrees(lat, lng)
Пример #6
0
def get_flights(resources: ResourceSet, flights_url: str, area: s2sphere.LatLngRect, include_recent_positions: bool) -> Dict:
  resp = resources.dss_client.get(flights_url, params={
    'view': '{},{},{},{}'.format(
      area.lat_lo().degrees,
      area.lng_lo().degrees,
      area.lat_hi().degrees,
      area.lng_hi().degrees,
    ),
    'include_recent_positions': 'true' if include_recent_positions else 'false',
  }, scope=rid.SCOPE_READ)
  return _json_or_error(resp)
Пример #7
0
def _make_flight_observation(
        flight: rid.RIDFlight,
        view: s2sphere.LatLngRect) -> observation_api.Flight:
    paths: List[List[observation_api.Position]] = []
    current_path: List[observation_api.Position] = []
    previous_position: Optional[observation_api.Position] = None

    lat_min = view.lat_lo().degrees
    lat_max = view.lat_hi().degrees
    lng_min = view.lng_lo().degrees
    lng_max = view.lng_hi().degrees

    # Decompose recent positions into a list of contiguous paths
    for p in flight.recent_positions:
        lat = p.position.lat
        lng = p.position.lng
        position_report = observation_api.Position(lat=lat,
                                                   lng=lng,
                                                   alt=p.position.alt)

        inside_view = lat_min <= lat <= lat_max and lng_min <= lng <= lng_max
        if inside_view:
            # This point is inside the view
            if not current_path and previous_position:
                # Positions were previously outside the view but this one is in
                current_path.append(previous_position)
            current_path.append(position_report)
        else:
            # This point is outside the view
            if current_path:
                # Positions were previously inside the view but this one is out
                current_path.append(position_report)
                paths.append(current_path)
                current_path = []
        previous_position = position_report
    if current_path:
        paths.append(current_path)

    return observation_api.Flight(
        id=flight.id,
        most_recent_position=observation_api.Position(
            lat=flight.current_state.position.lat,
            lng=flight.current_state.position.lng,
            alt=flight.current_state.position.alt),
        recent_paths=[observation_api.Path(positions=path) for path in paths])
Пример #8
0
def flights(utm_client: infrastructure.DSSTestSession, flights_url: str,
            area: s2sphere.LatLngRect,
            include_recent_positions: bool) -> FetchedUSSFlights:
    result = fetch.query_and_describe(
        utm_client,
        'GET',
        flights_url,
        params={
            'view':
            '{},{},{},{}'.format(
                area.lat_lo().degrees,
                area.lng_lo().degrees,
                area.lat_hi().degrees,
                area.lng_hi().degrees,
            ),
            'include_recent_positions':
            'true' if include_recent_positions else 'false',
        },
        scope=rid.SCOPE_READ)
    return FetchedUSSFlights(result)