Example #1
0
    def testStripe(self):

        # Create a new stripe
        red = czml.Color(rgba=(255, 0, 0, 64))
        grn = czml.Color(rgba=(0, 255, 0, 64))
        s = czml.Stripe()
        s.orientation = 'HORIZONTAL'
        s.evenColor = red
        s.oddColor = grn
        s.offset = 1.5
        s.repeat = 3.6
        self.assertEqual(
            s.data(), {
                'orientation': 'HORIZONTAL',
                'evenColor': {
                    'rgba': [255, 0, 0, 64]
                },
                'oddColor': {
                    'rgba': [0, 255, 0, 64]
                },
                'offset': 1.5,
                'repeat': 3.6
            })

        # Create a new stripe from an existing stripe
        s2 = czml.Stripe()
        s2.loads(s.dumps())
        self.assertEqual(s.data(), s2.data())
Example #2
0
    def testColor(self):

        col = czml.Color()
        col.rgba = [0, 255, 127]
        self.assertEqual(col.rgba, [0, 255, 127, 1])
        col.rgba = [0, 255, 127, 55]
        self.assertEqual(col.rgba, [0, 255, 127, 55])
        now = datetime.now()
        col.rgba = [now, 0, 255, 127, 55]
        self.assertEqual(col.rgba, [now.isoformat(), 0, 255, 127, 55])
        y2k = datetime(2000, 1, 1)
        col.rgba = [now, 0, 255, 127, 55, y2k.isoformat(), 5, 6, 7, 8]
        self.assertEqual(
            col.rgba,
            [now.isoformat(), 0, 255, 127, 55,
             y2k.isoformat(), 5, 6, 7, 8])
        col.rgba = [1, 0, 255, 127, 55, 2, 5, 6, 7, 8]
        self.assertEqual(col.rgba, [1, 0, 255, 127, 55, 2, 5, 6, 7, 8])
        col.rgbaf = [
            now, 0, 0.255, 0.127, 0.55,
            y2k.isoformat(), 0.5, 0.6, 0.7, 0.8
        ]
        self.assertEqual(col.rgbaf, [
            now.isoformat(), 0.0, 0.255, 0.127, 0.55,
            y2k.isoformat(), 0.5, 0.6, 0.7, 0.8
        ])
        col2 = czml.Color()
        col2.loads(col.dumps())
        self.assertEqual(col.data(), col2.data())
Example #3
0
    def testGrid(self):

        # Create a new grid
        red = czml.Color(rgba=(255, 0, 0, 64))
        g = czml.Grid()
        g.color = red
        g.cellAlpha = 0.5
        g.lineCount = 4
        g.lineThickness = 1.5
        g.lineOffset = 0.75
        self.assertEqual(
            g.data(), {
                'color': {
                    'rgba': [255, 0, 0, 64]
                },
                'cellAlpha': 0.5,
                'lineCount': 4,
                'lineThickness': 1.5,
                'lineOffset': 0.75
            })

        # Create a new grid from an existing grid
        g2 = czml.Grid()
        g2.loads(g.dumps())
        self.assertEqual(g.data(), g2.data())
Example #4
0
    def testMaterial(self):
        red = czml.Color(rgba=(255, 0, 0, 64))
        mat = czml.Material(solidColor={'color': red})
        mat.solidColor = {'color': red}
        mat_dict = {'solidColor': {'color': {'rgba': [255, 0, 0, 64]}}}
        self.assertEqual(mat.data(), mat_dict)

        mat2 = czml.Material(**mat_dict)
        self.assertEqual(mat.data(), mat2.data())
Example #5
0
    def testSolidColor(self):

        # Create a new solidcolor
        red = czml.Color(rgba=(255, 0, 0, 64))
        sc = czml.SolidColor()
        sc.color = red
        self.assertEqual(sc.data(), {'color': {'rgba': [255, 0, 0, 64]}})

        # Create a new solidcolor from an existing solidcolor
        sc2 = czml.SolidColor()
        sc2.loads(sc.dumps())
        self.assertEqual(sc.data(), sc2.data())
Example #6
0
    def testPolylineOutline(self):

        # Create a new polylineoutline
        red = czml.Color(rgba=(255, 0, 0, 64))
        grn = czml.Color(rgba=(0, 255, 0, 64))
        po = czml.PolylineOutline()
        po.color = red
        po.outlineColor = grn
        po.outlineWidth = 4
        self.assertEqual(
            po.data(), {
                'color': {
                    'rgba': [255, 0, 0, 64]
                },
                'outlineColor': {
                    'rgba': [0, 255, 0, 64]
                },
                'outlineWidth': 4
            })

        # Create a new polylineoutline from an existing polylineoutline
        po2 = czml.PolylineOutline()
        po2.loads(po.dumps())
        self.assertEqual(po.data(), po2.data())
Example #7
0
    def testMaterial(self):

        # Create a new material
        red = czml.Color(rgba=(255, 0, 0, 64))
        mat = czml.Material()
        mat.solidColor = {'color': red}
        self.assertEqual(mat.data(),
                         {'solidColor': {
                             'color': {
                                 'rgba': [255, 0, 0, 64]
                             }
                         }})

        # Create a new material from an existing material
        mat2 = czml.Material()
        mat2.loads(mat.dumps())
        self.assertEqual(mat.data(), mat2.data())
Example #8
0
    def testPolylineGlow(self):

        # Create a new polylineglow
        red = czml.Color(rgba=(255, 0, 0, 64))
        pg = czml.PolylineGlow()
        pg.color = red
        pg.glowPower = 0.25
        self.assertEqual(pg.data(), {
            'color': {
                'rgba': [255, 0, 0, 64]
            },
            'glowPower': 0.25
        })

        # Create a new polylineglow from an existing polylineglow
        pg2 = czml.PolylineGlow()
        pg2.loads(pg.dumps())
        self.assertEqual(pg.data(), pg2.data())
Example #9
0
    def czml(self):

        doc = czml.CZML();
        iso = self.date.isoformat()

        # Generate time-specific lists for various objects
        central_polyline_degrees = []
        north_polyline_degrees = []
        south_polyline_degrees = []
        ellipse_position = []
        ellipse_semiMajorAxis = []
        ellipse_semiMinorAxis = []
        ellipse_rotation = []

        for t in range(len(self.time)):

            time = iso + "T" + self.time[t] + ":00Z"

            # Define polyline waypoints only where data exist
            if self.position['north'][t] != None:
                north_polyline_degrees += [self.position['north'][t][0], self.position['north'][t][1], 0.0]
            if self.position['central'][t] != None:
                central_polyline_degrees += [self.position['central'][t][0], self.position['central'][t][1], 0.0]
            if self.position['south'][t] != None:
                south_polyline_degrees += [self.position['south'][t][0], self.position['south'][t][1], 0.0]

            # Define ellipse positions and attributes for every time in the interval, using limits where necessary
            use_limit = min(int(math.floor(t/(len(self.time)/2))),1)
            if self.position['north'][t] == None:
                north = self.limits['north'][use_limit]
            else:
                north = self.position['north'][t]
            if self.position['central'][t] == None:
                central = self.limits['central'][use_limit]
            else:
                central = self.position['central'][t]
            if self.position['south'][t] == None:
                south = self.limits['south'][use_limit]
            else:
                south = self.position['south'][t]

            # Approximate ellipse semiMajorAxis from vincenty distance between limit polylines
            north2 = (north[1], north[0])
            south2 = (south[1], south[0])
            semi_major_axis = vincenty(north2, south2).meters / 2

            # Approximate elipse semiMinorAxis from sun altitude (probably way wrong!)
            ellipse_axis_ratio = self.sun_altitude[t] / 90
            semi_minor_axis = semi_major_axis * ellipse_axis_ratio

            # Approximate ellipse rotation using basic spheroid (TODO: replace with WGS-84)
            # Calculate bearing in both directions and average them
            nlat = north[1]/180 * math.pi;
            nlon = north[0]/180 * math.pi;
            clat = central[1]/180 * math.pi;
            clon = central[0]/180 * math.pi;
            slat = south[1]/180 * math.pi;
            slon = south[0]/180 * math.pi;

            y = math.sin(slon-nlon) * math.cos(slat);
            x = math.cos(nlat) * math.sin(slat) - math.sin(nlat) * math.cos(slat) * math.cos(slon-nlon);
            initial_bearing = math.atan2(y, x)
            if (initial_bearing < 0):
                initial_bearing += math.pi * 2

            y = math.sin(nlon-slon) * math.cos(nlat);
            x = math.cos(slat) * math.sin(nlat) - math.sin(slat) * math.cos(nlat) * math.cos(nlon-slon);
            final_bearing = math.atan2(y, x) - math.pi
            if (final_bearing < 0):
                final_bearing += math.pi * 2

            rotation = -1 * ((initial_bearing + final_bearing) / 2 - (math.pi / 2))

            ellipse_position += [time, central[0], central[1], 0.0]
            ellipse_semiMajorAxis += [time, round(semi_major_axis, 3)]
            ellipse_semiMinorAxis += [time, round(semi_minor_axis, 3)]
            ellipse_rotation += [time, round(rotation, 3)]        

        # Generate document packet with clock
        start_time = iso + "T" + self.time[0] + ":00Z"
        end_time = iso + "T" + self.time[-1] + ":00Z"
        packet = czml.CZMLPacket(id='document',version='1.0')
        c = czml.Clock()
        c.multiplier = 300
        c.range = "LOOP_STOP"
        c.step = "SYSTEM_CLOCK_MULTIPLIER"
        c.currentTime = start_time
        c.interval = start_time + "/" + end_time
        packet.clock = c
        doc.packets.append(packet)

        # Generate a polyline packet for the north and south polylines, connected and filled
        limit_polyline_degrees = list(north_polyline_degrees)
        point = len(south_polyline_degrees)/3
        while (point > 0):
            offset = (point-1) * 3
            limit_polyline_degrees += [ south_polyline_degrees[offset],
                                        south_polyline_degrees[offset+1],
                                        south_polyline_degrees[offset+2] ]
            point -= 1
        packet_id = iso + '_bounds_polygon'
        packet = czml.CZMLPacket(id=packet_id)
        boc = czml.Color(rgba=(232, 72, 68, 255))
        bsc = czml.SolidColor(color=czml.Color(rgba=(0, 0, 0, 66)))
        bmat = czml.Material(solidColor=bsc)
        bdeg = limit_polyline_degrees
        bpos = czml.Positions(cartographicDegrees=bdeg)
        bpg = czml.Polygon(show=True, height=0, outline=True, outlineColor=boc, outlineWidth=2, material=bmat, positions=bpos)
        packet.polygon = bpg
        doc.packets.append(packet)

        # Generate central polyline packet
        packet_id = iso + '_central_polyline'
        packet = czml.CZMLPacket(id=packet_id)
        csc = czml.SolidColor(color=czml.Color(rgba=(241, 226, 57, 255)))
        cmat = czml.Material(solidColor=csc)
        cpos = czml.Positions(cartographicDegrees=central_polyline_degrees)
        cpl = czml.Polyline(show=True, width=4, followSurface=True, material=cmat, positions=cpos)
        packet.polyline = cpl
        doc.packets.append(packet)

        # Generate ellipse shadow packet
        packet_id = iso + '_shadow_ellipse'
        packet = czml.CZMLPacket(id=packet_id)
        esc = czml.SolidColor(color=czml.Color(rgba=(0, 0, 0, 160)))
        emat = czml.Material(solidColor=esc)
        xmaj = czml.Number(ellipse_semiMajorAxis)
        xmin = czml.Number(ellipse_semiMinorAxis)
        rot = czml.Number(ellipse_rotation)
        ell = czml.Ellipse(show=True, fill=True, granularity=0.002, material=emat, semiMajorAxis=xmaj, semiMinorAxis=xmin, rotation=rot)
        packet.ellipse = ell
        packet.position = czml.Position(cartographicDegrees=ellipse_position)
        doc.packets.append(packet)

        return list(doc.data())