Пример #1
0
def czml_from_feature_collection(fc, name):
    packets = []
    for feat in fc:
        packets.append(packet_from_geofeature(feat))

    document = Document([Preamble(name=name), *packets])

    return document
Пример #2
0
def write_rx_czml():
    height = 50
    receiver_point_packets = []
    lob_packets = []
    top = Preamble(name="Receivers")

    rx_properties = {
        "verticalOrigin": "BOTTOM",
        "scale": 0.75,
        "heightReference":"CLAMP_TO_GROUND",
        "height": 48,
        "width": 48,
    }

    for index, x in enumerate(receivers):
        if x.isActive and ms.receiving:
            lob_start_lat = x.latitude
            lob_start_lon = x.longitude
            lob_stop_lat, lob_stop_lon = v.direct(lob_start_lat, lob_start_lon, x.doa, d)
            lob_packets.append(Packet(id=f"LOB-{x.station_id}-{index}",
            polyline=Polyline(
                material= Material( polylineOutline =
                    PolylineOutlineMaterial(
                        color= Color(rgba=[255, 140, 0, 255]),
                        outlineColor= Color(rgba=[0, 0, 0, 255]),
                        outlineWidth= 2
                )),
                clampToGround=True,
                width=5,
                positions=Position(cartographicDegrees=[lob_start_lon, lob_start_lat, height, lob_stop_lon, lob_stop_lat, height])
            )))
        else:
            lob_packets = []

        if x.isMobile == True:
            rx_icon = {"image":{"uri":"/static/flipped_car.svg"}}
            # if x.heading > 0 or x.heading < 180:
            #     rx_icon = {"image":{"uri":"/static/flipped_car.svg"}, "rotation":math.radians(360 - x.heading + 90)}
            # elif x.heading < 0 or x.heading > 180:
            #     rx_icon = {"image":{"uri":"/static/car.svg"}, "rotation":math.radians(360 - x.heading - 90)}
        else:
            rx_icon = {"image":{"uri":"/static/tower.svg"}}
        receiver_point_packets.append(Packet(id=f"{x.station_id}-{index}",
        billboard={**rx_properties, **rx_icon},
        position={"cartographicDegrees": [ x.longitude, x.latitude, 15 ]}))

    output = Document([top] + receiver_point_packets + lob_packets)

    return output
Пример #3
0
def test_make_czml_png_rectangle_file(image):
    wsen = [20, 40, 21, 41]

    rectangle_packet = Packet(
        id="id_00",
        rectangle=Rectangle(
            coordinates=RectangleCoordinates(wsenDegrees=wsen),
            fill=True,
            material=Material(image=ImageMaterial(
                transparent=True,
                repeat=None,
                image="data:image/png;base64," + image,
            ), ),
        ),
    )

    with tempfile.NamedTemporaryFile(mode="w", suffix=".czml") as out_file:
        out_file.write(str(Document([Preamble(), rectangle_packet])))
        exists = os.path.isfile(out_file.name)

        # TODO: Should we be testing something else?
        assert exists
Пример #4
0
def test_preamble_has_given_name():
    expected_name = "document_00"
    preamble = Preamble(name=expected_name)

    assert preamble.name == expected_name
Пример #5
0
def test_preamble_has_proper_id_and_expected_version():
    preamble = Preamble()

    assert preamble.id == "document"
    assert preamble.version == CZML_VERSION
Пример #6
0
def write_czml(best_point, all_the_points, ellipsedata):
    point_properties = {
        "pixelSize":5.0,
        "heightReference":"CLAMP_TO_GROUND",
        # "heightReference":"RELATIVE_TO_GROUND",
      #   "color": {
      #       "rgba": [255, 0, 0, 255],
      # }
    }
    best_point_properties = {
        "pixelSize":12.0,
        # "heightReference":"RELATIVE_TO_GROUND",
        "heightReference":"CLAMP_TO_GROUND",
        "color": {
            "rgba": [0, 255, 0, 255],
      }
    }

    ellipse_properties = {
        "granularity": 0.008722222,
        "material": {
            "solidColor": {
                "color": {
                    "rgba": [255, 0, 0, 90]
                    }
                }
            }
        }

    top = Preamble(name="Geolocation Data")
    all_point_packets = []
    best_point_packets = []
    ellipse_packets = []

    if len(all_the_points) > 0 and (ms.plotintersects or ms.eps == 0):
        all_the_points = np.array(all_the_points)
        scaled_time = minmax_scale(all_the_points[:,-1])
        all_the_points = np.column_stack((all_the_points, scaled_time))
        for x in all_the_points:
            rgb = hsvtorgb(x[-1]/3, 0.9, 0.9)
            color_property = {"color":{"rgba": [*rgb, 255]}}
            all_point_packets.append(Packet(id=str(x[1]) + ", " + str(x[0]),
            point={**point_properties, **color_property},
            position={"cartographicDegrees": [ x[0], x[1], 20 ]},
            ))

    if len(best_point) > 0:
        for x in best_point:
            best_point_packets.append(Packet(id=str(x[0]) + ", " + str(x[1]),
            point=best_point_properties,
            position={"cartographicDegrees": [ x[1], x[0], 15 ]}))

    if len(ellipsedata) > 0:
        for x in ellipsedata:
            # rotation = 2 * np.pi - x[2]
            if x[0] >= x[1]:
                semiMajorAxis = x[0]
                semiMinorAxis = x[1]
                rotation = 2 * np.pi - x[2]
                rotation += np.pi/2
                # print(f"{x[4], x[3]} is inveted")
            else:
                rotation = x[2]
                semiMajorAxis = x[1]
                semiMinorAxis = x[0]
                # print(f"{x[4], x[3]} is NOT inveted")

            ellipse_info = {"semiMajorAxis": semiMajorAxis, "semiMinorAxis": semiMinorAxis, "rotation": rotation}
            ellipse_packets.append(Packet(id=str(x[4]) + ", " + str(x[3]),
            ellipse={**ellipse_properties, **ellipse_info},
            position={"cartographicDegrees": [ x[3], x[4], 15 ]}))

    output = Document([top] + best_point_packets + all_point_packets + ellipse_packets)

    return output
Пример #7
0
def test_preamble_has_given_description():
    expected_description = "czml document description"
    preamble = Preamble(description=expected_description)

    assert preamble.description == expected_description
Пример #8
0
def write_czml(best_point, all_the_points, ellipsedata):
    point_properties = {
        "pixelSize": 5.0,
        "heightReference": "RELATIVE_TO_GROUND",
        #   "color": {
        #       "rgba": [255, 0, 0, 255],
        # }
    }
    best_point_properties = {
        "pixelSize": 12.0,
        "heightReference": "RELATIVE_TO_GROUND",
        "color": {
            "rgba": [0, 255, 0, 255],
        }
    }
    rx_properties = {
        "image": {
            "uri": "/static/tower.svg"
        },
        # "rotation": "Cesium.Math.PI_OVER_FOUR",
        "verticalOrigin": "BOTTOM",
        "scale": 0.75,
        "heightReference": "RELATIVE_TO_GROUND",
        "height": 48,
        "width": 48
    }

    ellipse_properties = {
        "granularity": 0.008722222,
        "material": {
            "solidColor": {
                "color": {
                    "rgba": [255, 0, 0, 90]
                }
            }
        }
    }

    top = Preamble(name="Geolocation Data")
    all_point_packets = []
    best_point_packets = []
    receiver_point_packets = []
    ellipse_packets = []

    if all_the_points != None and (ms.plotintersects or ms.eps == 0):
        all_the_points = np.array(all_the_points)
        scaled_time = minmax_scale(all_the_points[:, -1])
        all_the_points = np.column_stack((all_the_points, scaled_time))
        for x in all_the_points:
            rgb = hsvtorgb(x[-1] / 3, 0.8, 0.8)
            color_property = {"color": {"rgba": [*rgb, 255]}}
            all_point_packets.append(
                Packet(
                    id=str(x[1]) + ", " + str(x[0]),
                    point={
                        **point_properties,
                        **color_property
                    },
                    position={"cartographicDegrees": [x[0], x[1], 10]},
                ))

    if best_point != None:
        for x in best_point:
            best_point_packets.append(
                Packet(id=str(x[0]) + ", " + str(x[1]),
                       point=best_point_properties,
                       position={"cartographicDegrees": [x[1], x[0], 15]}))

    if ellipsedata != None:
        for x in ellipsedata:
            # rotation = 2 * np.pi - x[2]
            if x[0] >= x[1]:
                semiMajorAxis = x[0]
                semiMinorAxis = x[1]
                rotation = 2 * np.pi - x[2]
                rotation += np.pi / 2
                # print(f"{x[4], x[3]} is inveted")
            else:
                rotation = x[2]
                semiMajorAxis = x[1]
                semiMinorAxis = x[0]
                # print(f"{x[4], x[3]} is NOT inveted")

            ellipse_info = {
                "semiMajorAxis": semiMajorAxis,
                "semiMinorAxis": semiMinorAxis,
                "rotation": rotation
            }
            ellipse_packets.append(
                Packet(id=str(x[4]) + ", " + str(x[3]),
                       ellipse={
                           **ellipse_properties,
                           **ellipse_info
                       },
                       position={"cartographicDegrees": [x[3], x[4], 15]}))

    for x in receivers:
        receiver_point_packets.append(
            Packet(id=x.station_id,
                   billboard=rx_properties,
                   position={
                       "cartographicDegrees": [x.longitude, x.latitude, 15]
                   }))

    with open("static/output.czml", "w") as file1:
        file1.write(
            str(
                Document([top] + best_point_packets + all_point_packets +
                         receiver_point_packets + ellipse_packets)))
Пример #9
0
    Material,
    Path,
    Position,
    SolidColorMaterial,
)
from czml3.types import IntervalValue, Sequence, TimeInterval

accesses_id = "9927edc4-e87a-4e1f-9b8b-0bfb3b05b227"
start = dt.datetime(2012, 3, 15, 10, tzinfo=dt.timezone.utc)
end = dt.datetime(2012, 3, 16, 10, tzinfo=dt.timezone.utc)

simple = Document(
    [
        Preamble(
            name="simple",
            clock=IntervalValue(
                start=start, end=end, value=Clock(currentTime=start, multiplier=60)
            ),
        ),
        Packet(id=accesses_id, name="Accesses", description="List of Accesses"),
        Packet(
            id="Satellite/Geoeye1-to-Satellite/ISS",
            name="Geoeye1 to ISS",
            parent=accesses_id,
            availability=Sequence(
                [
                    TimeInterval(
                        start="2012-03-15T10:16:06.97400000000198Z",
                        end="2012-03-15T10:33:59.3549999999959Z",
                    ),
                    TimeInterval(
                        start="2012-03-15T11:04:09.73799999999756Z",