示例#1
0
        public void NewPacketWritesObjectLiteral()
        {
            PacketCesiumWriter packet = m_writer.OpenPacket(m_output);

            packet.Close();

            Assert.AreEqual("{}", m_sw.ToString());
        }
        public void NewPacketWritesObjectLiteral()
        {
            var packet = m_writer.OpenPacket(m_outputStream);

            packet.Close();

            Assert.AreEqual("{}", m_stringWriter.ToString());
        }
 public void DisposeClosesPacket()
 {
     using (PacketCesiumWriter packet = m_writer.OpenPacket(m_output))
     {
     }
     Assert.AreEqual("{}", m_sw.ToString());
 }
示例#4
0
        public void DisposeClosesPacket()
        {
            using (m_writer.OpenPacket(m_outputStream))
            {
            }

            Assert.AreEqual("{}", m_stringWriter.ToString());
        }
 public void TestCesiumPropertyWriterSetUp()
 {
     StringWriter = new StringWriter();
     OutputStream = new CesiumOutputStream(StringWriter);
     Writer       = new CesiumStreamWriter();
     Packet       = Writer.OpenPacket(OutputStream);
 }
        public void CreateExampleFile()
        {
            using (var stringWriter = new StringWriter())
            {
                var output = new CesiumOutputStream(stringWriter)
                {
                    PrettyFormatting = true
                };
                var writer = new CesiumStreamWriter();

                using (var packet = writer.OpenPacket(output))
                {
                    packet.WriteId("MyID");

                    var startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0));
                    var stopDate  = new JulianDate(new GregorianDate(2012, 4, 2, 12, 1, 0));

                    using (var clockWriter = packet.OpenClockProperty())
                    {
                        using (var intervalClockWriter = clockWriter.OpenInterval(startDate, stopDate))
                        {
                            intervalClockWriter.WriteCurrentTime(startDate);
                        }
                    }

                    using (var modelWriter = packet.OpenModelProperty())
                    {
                        modelWriter.WriteGltfProperty(new Uri("example.gltf", UriKind.Relative), CesiumResourceBehavior.LinkTo);

                        using (var nodeTransformationsWriter = modelWriter.OpenNodeTransformationsProperty())
                        {
                            using (var nodeTransformationWriter = nodeTransformationsWriter.OpenNodeTransformationProperty("node1"))
                            {
                                nodeTransformationWriter.WriteScaleProperty(new Cartesian(1.0, 2.0, 3.0));
                                nodeTransformationWriter.WriteRotationProperty(UnitQuaternion.Identity);
                                nodeTransformationWriter.WriteTranslationProperty(new Cartesian(4.0, 5.0, 6.0));
                            }

                            using (var nodeTransformationWriter = nodeTransformationsWriter.OpenNodeTransformationProperty("node2"))
                            {
                                var dates = new List <JulianDate>
                                {
                                    startDate,
                                    stopDate
                                };
                                var values = new List <Cartesian>
                                {
                                    new Cartesian(1.0, 2.0, 3.0),
                                    new Cartesian(10.0, 12.0, 14.0)
                                };
                                nodeTransformationWriter.WriteScaleProperty(dates, values);
                            }
                        }
                    }
                }

                Console.WriteLine(stringWriter.ToString());
            }
        }
示例#7
0
        public void CreateExampleFile()
        {
            using (var stringWriter = new StringWriter())
            {
                var output = new CesiumOutputStream(stringWriter)
                {
                    PrettyFormatting = true
                };
                var writer = new CesiumStreamWriter();

                using (var packet = writer.OpenPacket(output))
                {
                    packet.WriteId("MyID");

                    var startDate = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0));
                    var stopDate  = new JulianDate(new GregorianDate(2012, 4, 2, 12, 1, 0));

                    using (var clockWriter = packet.OpenClockProperty())
                    {
                        using (var intervalClockWriter = clockWriter.OpenInterval(startDate, stopDate))
                        {
                            intervalClockWriter.WriteCurrentTime(startDate);
                        }
                    }

                    using (var modelWriter = packet.OpenModelProperty())
                    {
                        modelWriter.WriteGltfProperty(new Uri("example.gltf", UriKind.Relative), CesiumResourceBehavior.LinkTo);

                        using (var articulationsWriter = modelWriter.OpenArticulationsProperty())
                        {
                            using (var articulationWriter = articulationsWriter.OpenArticulationProperty("articulation1 stage1"))
                            {
                                articulationWriter.WriteNumber(45);
                            }

                            using (var articulationWriter = articulationsWriter.OpenArticulationProperty("articulation1 stage2"))
                            {
                                var dates = new List <JulianDate>
                                {
                                    startDate,
                                    stopDate
                                };
                                var values = new List <double>
                                {
                                    1.0,
                                    10.0
                                };
                                articulationWriter.WriteNumber(dates, values);
                            }
                        }
                    }
                }

                Console.WriteLine(stringWriter.ToString());
            }
        }
        public void TestExample()
        {
            var outputStream = new CesiumOutputStream(StringWriter)
            {
                PrettyFormatting = true
            };
            var writer = new CesiumStreamWriter();

            using (var packet = writer.OpenPacket(outputStream))
            {
                packet.WriteId("examplePolygon");

                using (var polygon = packet.OpenPolygonProperty())
                {
                    using (var positions = polygon.OpenPositionsProperty())
                    {
                        var listOfPositions = new List <Cartographic> {
                            new Cartographic(0, 0, 0), new Cartographic(0, 10, 0), new Cartographic(10, 10, 0), new Cartographic(10, 0, 0),
                        };
                        positions.WriteCartographicDegrees(listOfPositions);
                    }

                    using (var holes = polygon.OpenHolesProperty())
                    {
                        var listOfHoles = new List <List <Cartographic> >
                        {
                            new List <Cartographic> {
                                new Cartographic(1, 1, 0), new Cartographic(1, 2, 0), new Cartographic(2, 2, 0),
                            },
                            new List <Cartographic> {
                                new Cartographic(4, 4, 0), new Cartographic(4, 5, 0), new Cartographic(5, 5, 0), new Cartographic(5, 4, 0),
                            },
                        };
                        holes.WriteCartographicDegrees(listOfHoles);
                    }

                    using (var material = polygon.OpenMaterialProperty())
                    {
                        using (var solidColor = material.OpenSolidColorProperty())
                        {
                            solidColor.WriteColorProperty(Color.Red);
                        }
                    }
                }
            }

            Console.WriteLine(StringWriter.ToString());
        }
示例#9
0
        public void RunExample()
        {
            var stringWriter = new StringWriter();
            var output       = new CesiumOutputStream(stringWriter)
            {
                PrettyFormatting = true
            };

            var stream = new CesiumStreamWriter();

            using (var packet = stream.OpenPacket(output))
            {
                packet.WriteId("Test");

                using (var billboard = packet.OpenBillboardProperty())
                {
                    billboard.WriteColorProperty(123, 67, 0, 255);
                    billboard.WriteImageProperty(new Uri("http://cesiumjs.org/images/CesiumHeaderLogo.png"), CesiumResourceBehavior.LinkTo);
                }

                using (var position = packet.OpenPositionProperty())
                {
                    position.WriteCartographicDegrees(new Cartographic(-75.0, 45.0, 100.0));
                }

                using (var model = packet.OpenModelProperty())
                    using (var color = model.OpenColorProperty())
                        using (var intervals = color.OpenMultipleIntervals())
                        {
                            var start = new GregorianDate(2012, 8, 4, 16, 0, 0).ToJulianDate();
                            var stop  = new GregorianDate(2012, 8, 4, 16, 1, 0).ToJulianDate();

                            using (var interval = intervals.OpenInterval(start, stop))
                            {
                                interval.WriteRgbaf(Color.Red);
                            }

                            start = new GregorianDate(2012, 8, 4, 16, 1, 0).ToJulianDate();
                            stop  = new GregorianDate(2012, 8, 4, 16, 2, 0).ToJulianDate();
                            using (var interval = intervals.OpenInterval(start, stop))
                            {
                                interval.WriteRgbaf(Color.Lime);
                            }
                        }
            }

            Console.WriteLine(stringWriter.ToString());
        }
示例#10
0
        public void TestCompleteExample()
        {
            var date = new JulianDate(2451545.0);

            const string id           = "MyID";
            var          availability = new TimeInterval(date, date.AddDays(2.0));

            var interval1 = new TimeInterval(date, date.AddDays(1.0));

            var interval1Position    = new Cartesian(1.0, 2.0, 3.0);
            var interval1Orientation = new UnitQuaternion(1, 0, 0, 0);

            var interval2 = new TimeInterval(date.AddDays(1.0), date.AddDays(2.0));

            var interval2SampleDates = new List <JulianDate>
            {
                date.AddDays(1.0),
                date.AddDays(1.5),
                date.AddDays(2.0)
            };

            var interval2SamplePositions = new List <Cartographic>
            {
                Cartographic.Zero,
                new Cartographic(1.0, 0.0, 0.0),
                new Cartographic(0.0, 1.0, 0.0)
            };
            var interval2SampleOrientations = new List <UnitQuaternion>
            {
                UnitQuaternion.Identity,
                new UnitQuaternion(0.0, 1.0, 0.0, 0.0),
                new UnitQuaternion(0.0, 0.0, 1.0, 0.0)
            };

            const CesiumInterpolationAlgorithm orientationInterpolationAlgorithm = CesiumInterpolationAlgorithm.Linear;
            const int orientationInterpolationDegree = 1;

            var outputStream = new CesiumOutputStream(StringWriter)
            {
                PrettyFormatting = true
            };
            var writer = new CesiumStreamWriter();

            using (var packet = writer.OpenPacket(outputStream))
            {
                packet.WriteId(id);
                packet.WriteAvailability(availability);

                using (var positionWriter = packet.OpenPositionProperty())
                    using (var intervalListWriter = positionWriter.OpenMultipleIntervals())
                    {
                        using (var interval = intervalListWriter.OpenInterval())
                        {
                            interval.WriteInterval(interval1);
                            interval.WriteCartesian(interval1Position);
                        }

                        using (var interval = intervalListWriter.OpenInterval(interval2.Start, interval2.Stop))
                        {
                            interval.WriteCartographicRadians(interval2SampleDates, interval2SamplePositions);
                        }
                    }

                using (var orientationWriter = packet.OpenOrientationProperty())
                    using (var intervalListWriter = orientationWriter.OpenMultipleIntervals())
                    {
                        using (var interval = intervalListWriter.OpenInterval())
                        {
                            interval.WriteInterval(interval1);
                            interval.WriteUnitQuaternion(interval1Orientation);
                        }

                        using (var interval = intervalListWriter.OpenInterval(interval2.Start, interval2.Stop))
                        {
                            interval.WriteInterpolationAlgorithm(orientationInterpolationAlgorithm);
                            interval.WriteInterpolationDegree(orientationInterpolationDegree);

                            interval.WriteUnitQuaternion(interval2SampleDates, interval2SampleOrientations);
                        }
                    }
            }

            Console.WriteLine(StringWriter.ToString());
        }
        public void CreateExampleFile()
        {
            using (var stringWriter = new StringWriter())
            {
                var output = new CesiumOutputStream(stringWriter, true);
                var writer = new CesiumStreamWriter();

                output.WriteStartSequence();

                using (var documentPacket = writer.OpenPacket(output))
                {
                    documentPacket.WriteId("document");
                    documentPacket.WriteVersion("1.0");
                    using (var clockWriter = documentPacket.OpenClockProperty())
                        using (var intervalClockWriter = clockWriter.OpenInterval(m_startDate, m_stopDate))
                        {
                            intervalClockWriter.WriteCurrentTime(m_startDate);
                        }
                }

                using (var packet = writer.OpenPacket(output))
                {
                    packet.WriteId("MyID");

                    using (var customPropertiesWriter = packet.OpenPropertiesProperty())
                    {
                        using (var customPropertyWriter = customPropertiesWriter.OpenCustomPropertyProperty("custom_boolean"))
                            using (var intervalListWriter = customPropertyWriter.OpenMultipleIntervals())
                            {
                                using (var intervalWriter = intervalListWriter.OpenInterval(m_startDate, m_startDate.AddSeconds(1)))
                                {
                                    intervalWriter.WriteBoolean(true);
                                }

                                using (var intervalWriter = intervalListWriter.OpenInterval(m_startDate.AddSeconds(1), m_startDate.AddSeconds(2)))
                                {
                                    intervalWriter.WriteBoolean(false);
                                }

                                using (var intervalWriter = intervalListWriter.OpenInterval(m_startDate.AddSeconds(2), m_stopDate))
                                {
                                    intervalWriter.WriteBoolean(true);
                                }
                            }

                        using (var customPropertyWriter = customPropertiesWriter.OpenCustomPropertyProperty("custom_cartesian"))
                        {
                            var dates  = new List <JulianDate>();
                            var values = new List <Cartesian>();

                            dates.Add(m_startDate);
                            values.Add(new Cartesian(1.0, 2.0, 3.0));

                            dates.Add(m_startDate.AddSeconds(60.0));
                            values.Add(new Cartesian(4.0, 5.0, 6.0));

                            dates.Add(m_startDate.AddSeconds(120.0));
                            values.Add(new Cartesian(7.0, 8.0, 9.0));

                            customPropertyWriter.WriteCartesian(dates, values);
                        }
                    }
                }

                output.WriteEndSequence();

                Console.WriteLine(stringWriter.ToString());
            }
        }
示例#12
0
        public ActionResult Info(int ID, Int64 lastdataid = 0)
        {
            var          flightmapdatas = db.FlightMapDatas.Where(x => x.FlightID == ID && (x.Altitude > 0 || x.Speed > 0) && x.FlightMapDataID > lastdataid).OrderBy(x => x.FlightMapDataID).ToList();
            int          count          = flightmapdatas.Count();
            MemoryStream ms             = new MemoryStream();
            var          outputStream   = new StreamWriter(ms);
            var          cesiumWriter   = new CesiumStreamWriter();
            var          output         = new CesiumOutputStream(outputStream)
            {
                // Since this is a demo, turning on PrettyFormatting makes the response easier to view
                // with web browser developer tools.  It just adds whitespace and newlines to the response,
                // so production environments would typically leave this turned off.
                PrettyFormatting = true
            };

            if (count > 0)
            {
                // The whole body of CZML must be wrapped in a JSON array, opened here.
                output.WriteStartSequence();

                FlightMapData firstItem = db.FlightMapDatas.Where(x => x.FlightID == ID && (x.Altitude > 0 || x.Speed > 0)).OrderBy(x => x.FlightMapDataID).ToList().Take(1).FirstOrDefault();

                FlightMapData       LastItem  = db.FlightMapDatas.Where(x => x.FlightID == ID && (x.Altitude > 0 || x.Speed > 0)).OrderBy(x => x.FlightMapDataID).ToList().LastOrDefault();
                JulianDate          StartTime = new JulianDate(firstItem.ReadTime.Value);
                JulianDate          EndTime   = new JulianDate(LastItem.ReadTime.Value);
                string              curFile   = @"C:\Cesium\test.czml";
                FileInfo            info      = new FileInfo(curFile);
                List <Cartographic> pList     = new List <Cartographic>();
                List <JulianDate>   JList     = new List <JulianDate>();
                List <Double>       HList     = new List <Double>();
                List <Double>       PList     = new List <Double>();
                List <Double>       RList     = new List <Double>();



                // The first packet (JSON object) of CZML must be the document packet.
                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("document");
                    entity.WriteVersion("1.0");
                    using (var clock = entity.OpenClockProperty())
                    {
                        clock.WriteInterval(new TimeInterval(StartTime, EndTime));
                        if (lastdataid == 0)
                        {
                            clock.WriteCurrentTime(StartTime);
                        }
                        else
                        {
                            clock.WriteCurrentTime(EndTime);
                        }

                        clock.WriteMultiplier(2);
                        clock.WriteStep(ClockStep.SystemClockMultiplier);
                    }
                    //}
                }
                // Open a new CZML packet for each point.
                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("Aircraft");
                    entity.WriteVersion("1.0");

                    entity.WriteAvailability(new TimeInterval(StartTime, EndTime));



                    using (var path = entity.OpenPathProperty())
                    {
                        using (var show = path.OpenShowProperty())
                        {
                            //if(lastdataid==0)
                            // show.WriteInterval(new TimeInterval(StartTime, EndTime));

                            show.WriteBoolean(true);
                        }

                        path.WriteWidthProperty(2);
                        using (var material = path.OpenMaterialProperty())
                        {
                            using (var sol = material.OpenSolidColorProperty())
                            {
                                sol.WriteColorProperty(0, 255, 255, 255);
                            }
                        }
                        path.WriteResolutionProperty(1200);
                    }



                    using (var position = entity.OpenPositionProperty())
                    {
                        foreach (FlightMapData fmp in flightmapdatas)
                        {
                            double       lat = Convert.ToDouble(fmp.Latitude);
                            double       lon = Convert.ToDouble(fmp.Longitude);
                            double       alt = Convert.ToDouble(fmp.Altitude);
                            Cartographic nC  = new Cartographic(lon, lat, alt);
                            pList.Add(nC);
                            JulianDate jd = new JulianDate(fmp.ReadTime.Value);
                            JList.Add(jd);
                            var heading = Convert.ToDouble(fmp.Heading);
                            HList.Add(heading);
                            var pitch = Convert.ToDouble(fmp.Pitch);
                            PList.Add(pitch);

                            var roll = Convert.ToDouble(fmp.Roll);
                            RList.Add(roll);
                        }
                        position.WriteCartographicDegrees(JList, pList);
                    }
                }

                // Now we generate some sample points and send them down.
                // Close the JSON array that wraps the entire CZML document.

                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("Custom");
                    entity.WriteVersion("1.0");
                    entity.WriteAvailability(new TimeInterval(StartTime, EndTime));
                    var custom = entity.OpenPropertiesProperty();
                    CustomPropertyCesiumWriter newpro = custom.OpenCustomPropertyProperty("heading");
                    newpro.AsNumber();
                    newpro.WriteNumber(JList, HList);
                    newpro.Close();

                    CustomPropertyCesiumWriter newroll = custom.OpenCustomPropertyProperty("roll");
                    newroll.AsNumber();

                    newroll.WriteNumber(JList, RList);
                    newroll.Close();
                    CustomPropertyCesiumWriter newpitch = custom.OpenCustomPropertyProperty("pitch");                    // newpitch.Open(output);
                    newpitch.AsNumber();

                    newpitch.WriteNumber(JList, PList);
                    newpitch.Close();
                    CustomPropertyCesiumWriter LastDataID = custom.OpenCustomPropertyProperty("lastdataid");

                    LastDataID.AsNumber();

                    LastDataID.WriteNumber(LastItem.FlightMapDataID);
                    LastDataID.Close();
                    custom.Close();
                }

                output.WriteEndSequence();

                //ms.Position = 0;

                //ms.Seek(0, SeekOrigin.Begin);
                outputStream.Flush();

                // }
            }

            ms.Seek(0, SeekOrigin.Begin);
            return(File(ms, "application/json"));
        }
        public void TestExample()
        {
            var stringWriter = new StringWriter();
            var outputStream = new CesiumOutputStream(stringWriter)
            {
                PrettyFormatting = true
            };
            var writer = new CesiumStreamWriter();

            outputStream.WriteStartSequence();

            using (var packet = writer.OpenPacket(outputStream))
            {
                packet.WriteId("document");
                packet.WriteName("CZML Geometries: Polyline Volume");
                packet.WriteVersion("1.0");
            }

            using (var packet = writer.OpenPacket(outputStream))
            {
                packet.WriteId("greenBox");
                packet.WriteName("Green box with beveled corners and outline");

                using (var polylineVolume = packet.OpenPolylineVolumeProperty())
                {
                    using (var positions = polylineVolume.OpenPositionsProperty())
                    {
                        positions.WriteCartographicDegrees(new List <Cartographic>
                        {
                            new Cartographic(-90.0, 32.0, 0),
                            new Cartographic(-90.0, 36.0, 100000),
                            new Cartographic(-94.0, 36.0, 0),
                        });
                    }

                    using (var shape = polylineVolume.OpenShapeProperty())
                    {
                        shape.WriteCartesian2(new List <Rectangular>
                        {
                            new Rectangular(-50000, -50000),
                            new Rectangular(50000, -50000),
                            new Rectangular(50000, 50000),
                            new Rectangular(-50000, 50000),
                        });
                    }

                    polylineVolume.WriteCornerTypeProperty(CesiumCornerType.Beveled);

                    using (var material = polylineVolume.OpenMaterialProperty())
                    {
                        using (var solidColor = material.OpenSolidColorProperty())
                        {
                            solidColor.WriteColorProperty(Color.FromArgb(128, Color.Lime));
                        }
                    }

                    polylineVolume.WriteOutlineProperty(true);
                    polylineVolume.WriteOutlineColorProperty(Color.Black);
                }
            }

            using (var packet = writer.OpenPacket(outputStream))
            {
                packet.WriteId("blueStar");
                packet.WriteName("Blue star with mitered corners and outline");

                using (var polylineVolume = packet.OpenPolylineVolumeProperty())
                {
                    using (var positions = polylineVolume.OpenPositionsProperty())
                    {
                        positions.WriteCartographicDegrees(new List <Cartographic>
                        {
                            new Cartographic(-95.0, 32.0, 0),
                            new Cartographic(-95.0, 36.0, 100000),
                            new Cartographic(-99.0, 36.0, 200000),
                        });
                    }

                    using (var shape = polylineVolume.OpenShapeProperty())
                    {
                        const int    arms   = 7;
                        const double rOuter = 70000.0;
                        const double rInner = 50000.0;

                        const double angle    = Math.PI / arms;
                        var          vertices = new List <Rectangular>();
                        for (int i = 0; i < 2 * arms; i++)
                        {
                            double r = i % 2 == 0 ? rOuter : rInner;
                            vertices.Add(new Rectangular(Math.Cos(i * angle) * r, Math.Sin(i * angle) * r));
                        }

                        shape.WriteCartesian2(vertices);
                    }

                    polylineVolume.WriteCornerTypeProperty(CesiumCornerType.Mitered);

                    using (var material = polylineVolume.OpenMaterialProperty())
                    {
                        using (var solidColor = material.OpenSolidColorProperty())
                        {
                            solidColor.WriteColorProperty(Color.Blue);
                        }
                    }
                }
            }

            outputStream.WriteEndSequence();

            Console.WriteLine(stringWriter.ToString());
        }
示例#14
0
        /// <summary>
        /// This handles the HTTP request by writing some example CZML into the response.
        /// </summary>
        /// <param name="context">The current HttpContext</param>
        public void ProcessRequest(HttpContext context)
        {
            // A more complex example could examine context.Request here for
            // inputs coming from the client-side application.

            // Set the response type for CZML, which is JSON.
            context.Response.ContentType = "application/json";

            // Create an output stream writer for the response.
            using (var outputStream = new StreamWriter(context.Response.OutputStream))
            {
                var cesiumWriter = new CesiumStreamWriter();
                var output       = new CesiumOutputStream(outputStream)
                {
                    // Since this is a demo, turning on PrettyFormatting makes the response easier to view
                    // with web browser developer tools.  It just adds whitespace and newlines to the response,
                    // so production environments would typically leave this turned off.
                    PrettyFormatting = true
                };

                // The whole body of CZML must be wrapped in a JSON array, opened here.
                output.WriteStartSequence();

                // The first packet (JSON object) of CZML must be the document packet.
                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("document");
                    entity.WriteVersion("1.0");
                }

                // Now we generate some sample points and send them down.
                for (int y = -3; y <= 3; ++y)
                {
                    double lat = y * 10.0;
                    for (int x = -18; x <= 18; ++x)
                    {
                        double lon = x * 9.99999999;

                        // Open a new CZML packet for each point.
                        using (var entity = cesiumWriter.OpenPacket(output))
                        {
                            entity.WriteId("point " + (x * 10) + " " + (y * 10));

                            using (var position = entity.OpenPositionProperty())
                            {
                                position.WriteCartographicDegrees(new Cartographic(lon, lat, 0.0));
                            }

                            using (var point = entity.OpenPointProperty())
                            {
                                point.WritePixelSizeProperty(10.0);
                                point.WriteColorProperty(Color.Yellow);
                            }

                            // Click any dot in Cesium Viewer to read its description.
                            using (var description = entity.OpenDescriptionProperty())
                            {
                                description.WriteString($@"
<table class=""cesium-infoBox-defaultTable"">
<tbody>
 <tr>
  <td>Longitude</td>
  <td>{lon:0} degrees</td>
 </tr>
 <tr>
  <td>Latitude</td>
  <td>{lat:0} degrees</td>
 </tr>
</tbody></table>");
                            }
                        }
                    }
                }

                // Close the JSON array that wraps the entire CZML document.
                output.WriteEndSequence();
            }
        }
        public void Sandbox()
        {
            JulianDate date = new JulianDate(2451545.0);

            using (StringWriter sw = new StringWriter())
            {
                CesiumOutputStream output = new CesiumOutputStream(sw);
                output.PrettyFormatting = true;
                CesiumStreamWriter writer = new CesiumStreamWriter();

                using (PacketCesiumWriter packet = writer.OpenPacket(output))
                {
                    packet.WriteId("MyID");
                    packet.WriteAvailability(date, date.AddDays(1.0));

                    using (PositionCesiumWriter position = packet.OpenPositionProperty())
                        using (CesiumIntervalListWriter <PositionCesiumWriter> intervalList = position.OpenMultipleIntervals())
                        {
                            using (PositionCesiumWriter interval = intervalList.OpenInterval())
                            {
                                interval.WriteInterval(new TimeInterval(date, date.AddDays(1.0)));
                                interval.WriteCartesian(new Cartesian(1.0, 2.0, 3.0));
                            }

                            using (PositionCesiumWriter interval = intervalList.OpenInterval(date.AddDays(1.0), date.AddDays(2.0)))
                            {
                                var dates     = new List <JulianDate>();
                                var positions = new List <Cartographic>();

                                dates.Add(date.AddDays(1.0));
                                positions.Add(Cartographic.Zero);

                                dates.Add(date.AddDays(1.5));
                                positions.Add(new Cartographic(1.0, 0.0, 0.0));

                                dates.Add(date.AddDays(2.0));
                                positions.Add(new Cartographic(0.0, 1.0, 0.0));

                                interval.WriteCartographicRadians(dates, positions);
                            }
                        }
                    using (OrientationCesiumWriter orientation = packet.OpenOrientationProperty())
                        using (CesiumIntervalListWriter <OrientationCesiumWriter> intervalList = orientation.OpenMultipleIntervals())
                        {
                            using (OrientationCesiumWriter interval = intervalList.OpenInterval())
                            {
                                interval.WriteAxes("MyMadeUpAxes");
                                interval.WriteInterval(new TimeInterval(date, date.AddDays(1.0)));
                                interval.WriteUnitQuaternion(new UnitQuaternion(1, 0, 0, 0));
                            }
                            using (OrientationCesiumWriter interval = intervalList.OpenInterval())
                            {
                                interval.WriteInterpolationAlgorithm(CesiumInterpolationAlgorithm.Linear);
                                interval.WriteInterpolationDegree(1);

                                var dates        = new List <JulianDate>();
                                var orientations = new List <UnitQuaternion>();

                                dates.Add(date.AddDays(1.0));
                                orientations.Add(UnitQuaternion.Identity);

                                dates.Add(date.AddDays(1.5));
                                orientations.Add(new UnitQuaternion(0.0, 1.0, 0.0, 0.0));

                                dates.Add(date.AddDays(2.0));
                                orientations.Add(new UnitQuaternion(0.0, 0.0, 1.0, 0.0));

                                interval.WriteUnitQuaternion(dates, orientations);
                            }
                        }
                }

                Console.WriteLine(sw.ToString());
            }
        }
示例#16
0
        public static void Main(string[] args)
        {
            // use a fixed seed so repeated invocations use the same colors
            var rng = new Random(0);

            var files = new[]
            {
                @"ISS11_07_image_data.csv",
                @"ISS11_11_image_data.csv",
                @"ISS12_01_image_data.csv",
                @"ISS12_07_2_image_data.csv",
                @"ISS12_11_image_data.csv",
                @"ISS13_01_image_data.csv",
                @"ISS11_04_image_data.csv"
            };

            List <KeyValuePair <string, string> > missions = new List <KeyValuePair <string, string> >();

            foreach (var fileName in files)
            {
                string   csvFile = Path.Combine(AssetsDirectory, "CSV", fileName);
                string[] lines   = File.ReadAllLines(csvFile);

                string czmlFile = Path.Combine(AssetsDirectory, "CZML", Path.ChangeExtension(fileName, ".czml"));
                string jsonFile = Path.Combine(AssetsDirectory, "JSON", Path.ChangeExtension(fileName, ".json"));

                using (StreamWriter czmlWriter = new StreamWriter(czmlFile))
                    using (StreamWriter jsonWriter = new StreamWriter(jsonFile))
                        using (CesiumOutputStream czmlOutputStream = new CesiumOutputStream(czmlWriter))
                        {
                            czmlOutputStream.PrettyFormatting = false;
                            czmlOutputStream.WriteStartSequence();

                            List <string> ID          = new List <string>();
                            List <string> Time        = new List <string>();
                            List <string> School      = new List <string>();
                            List <string> ImageUrl    = new List <string>();
                            List <string> LensSize    = new List <string>();
                            List <string> OrbitNumber = new List <string>();
                            List <string> FrameWidth  = new List <string>();
                            List <string> FrameHeight = new List <string>();
                            List <string> Page        = new List <string>();
                            List <string> CZML        = new List <string>();

                            GregorianDate start = new GregorianDate();
                            for (int i = 1; i < lines.Length; i++)
                            {
                                string   line   = lines[i];
                                string[] tokens = line.Split(',');
                                for (int q = 0; q < tokens.Length; q++)
                                {
                                    tokens[q] = tokens[q].Trim('"').Trim();
                                }

                                if (i == 1)
                                {
                                    start = GregorianDate.Parse(tokens[17]);
                                    missions.Add(new KeyValuePair <string, string>(Path.ChangeExtension(fileName, null), tokens[18]));
                                }
                                else if (i == lines.Length - 1)
                                {
                                    Console.WriteLine(Path.GetFileNameWithoutExtension(fileName));
                                    Console.WriteLine(start.ToJulianDate().TotalDays + " JDate");
                                    var stop = GregorianDate.Parse(tokens[17]);
                                    Console.WriteLine(stop.ToJulianDate().TotalDays + " JDate");
                                    Console.WriteLine();
                                    //Console.WriteLine((stop.ToJulianDate() - start.ToJulianDate()).TotalDays);
                                }

                                var writer = new CesiumStreamWriter();
                                using (var packet = writer.OpenPacket(czmlOutputStream))
                                {
                                    packet.WriteId(tokens[0]);
                                    using (var vertexPositions = packet.OpenVertexPositionsProperty())
                                    {
                                        var points = new Cartographic[] {
                                            new Cartographic(double.Parse(tokens[5]), double.Parse(tokens[6]), 0),
                                            new Cartographic(double.Parse(tokens[7]), double.Parse(tokens[8]), 0),
                                            new Cartographic(double.Parse(tokens[9]), double.Parse(tokens[10]), 0),
                                            new Cartographic(double.Parse(tokens[11]), double.Parse(tokens[12]), 0)
                                        };
                                        vertexPositions.WriteCartographicDegrees(points);
                                    }
                                    using (var polygon = packet.OpenPolygonProperty())
                                    {
                                        polygon.WriteShowProperty(true);
                                        using (var material = polygon.OpenMaterialProperty())
                                        {
                                            using (var color = material.OpenSolidColorProperty())
                                            {
                                                color.WriteColorProperty(Color.FromArgb(255, (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255)));
                                            }
                                        }
                                    }
                                }

                                for (int q = 0; q < tokens.Length; q++)
                                {
                                    tokens[q] = tokens[q].Replace("\"", "\\\"");
                                }

                                ID.Add(tokens[0]);
                                Time.Add(GregorianDate.Parse(tokens[17]).ToIso8601String(Iso8601Format.Compact));
                                School.Add(tokens[23]);
                                ImageUrl.Add(tokens[21].Split(new[] { '=' })[2]);
                                LensSize.Add(tokens[14]);
                                OrbitNumber.Add(tokens[19]);
                                FrameWidth.Add(tokens[15]);
                                FrameHeight.Add(tokens[16]);
                                Page.Add(tokens[20].Split(new[] { '=' })[1]);
                            }

                            czmlOutputStream.WriteEndSequence();

                            jsonWriter.WriteLine("{");
                            writeJsonArray(jsonWriter, "ID", ID);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "Time", Time);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "School", School);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "ImageUrl", ImageUrl);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "LensSize", LensSize);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "OrbitNumber", OrbitNumber);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "FrameWidth", FrameWidth);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "FrameHeight", FrameHeight);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "Page", Page);
                            jsonWriter.WriteLine();
                            jsonWriter.WriteLine("}");
                        }
            }

            using (StreamWriter missionsJsonWriter = new StreamWriter(Path.Combine(AssetsDirectory, "missions.json")))
            {
                missionsJsonWriter.Write("[");
                for (int i = 0; i < missions.Count; ++i)
                {
                    missionsJsonWriter.Write("{{\"file\":\"{0}\",\"name\":\"{1}\"}}", missions[i].Key, missions[i].Value);
                    if (i != missions.Count - 1)
                    {
                        missionsJsonWriter.Write(",");
                    }
                }
                missionsJsonWriter.Write("]");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";

            using (var outputStream = new StreamWriter(context.Response.OutputStream))
            {
                var cesiumWriter = new CesiumStreamWriter();
                var output       = new CesiumOutputStream(outputStream);

                output.PrettyFormatting = true;

                // The whole body of CZML must be wrapped in a JSON array, opened here.
                output.WriteStartSequence();

                // The first packet (JSON object) of CZML must be the document packet.
                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("document");
                    entity.WriteVersion("1.0");
                }


                // write an entity for each rocket launch phase

                var rocketData = new RocketTrajectoryData();

                var entities = rocketData.GetBetterRocketData();

                // get each phase


                foreach (var stage in entities.stages)
                {
                    var cartesianVelocitySet = GenerateCartesianVelocitySet(stage);

                    var clr   = GetNextColour();
                    var count = 0;
                    foreach (var positions in cartesianVelocitySet.Item2)
                    {
                        count++;

                        if (count % 100 == 0)
                        {
                            using (var packet = cesiumWriter.OpenPacket(output))
                            {
                                using (var point = packet.OpenPointProperty())
                                {
                                    point.WriteColorProperty(Color.Yellow);
                                    point.WritePixelSizeProperty(10.0);
                                }

                                using (var desc = packet.OpenDescriptionProperty())
                                {
                                    desc.WriteString("x,y,z:" + positions.Value.ToString());
                                }
                                using (var position = packet.OpenPositionProperty())
                                {
                                    position.WriteCartesian(positions.Value);
                                }
                            }
                        }
                    }



                    using (var packet = cesiumWriter.OpenPacket(output))
                    {
                        packet.WriteId("RocketLaunch");
                        using (var position = packet.OpenPositionProperty())
                        {
                            position.WriteCartesianVelocity(cartesianVelocitySet.Item1, cartesianVelocitySet.Item2);
                        }
                        using (var description = packet.OpenDescriptionProperty())
                        {
                            description.WriteString("This is the description of this element");
                        }

                        using (var path = packet.OpenPathProperty())
                        {
                            using (var material = path.OpenMaterialProperty())
                            {
                                using (var outline = material.OpenSolidColorProperty())
                                {
                                    using (var colour = outline.OpenColorProperty())
                                    {
                                        colour.WriteRgba(Color.DarkGoldenrod);
                                    }
                                }
                            }
                            path.WriteWidthProperty(8);
                            path.WriteLeadTimeProperty(10);
                            path.WriteTrailTimeProperty(1000);
                            path.WriteResolutionProperty(5);
                        }
                    }
                }

                output.WriteEndSequence();
            }
        }
示例#18
0
        // convert the distance of the downrange into a distance from the launch site, at a specific trajectory



        /// <summary>
        /// This handles the HTTP request by writing some example CZML into the response.
        /// </summary>
        /// <param name="context">The current HttpContext</param>
        public void ProcessRequest(HttpContext context)
        {
            // A more complex example could examine context.Request here for
            // inputs coming from the client-side application.

            // Set the response type for CZML, which is JSON.
            context.Response.ContentType = "application/json";

            // Create an output stream writer for the response.
            using (var outputStream = new StreamWriter(context.Response.OutputStream))
            {
                var cesiumWriter = new CesiumStreamWriter();
                var output       = new CesiumOutputStream(outputStream);

                // Since this is a demo, turning on PrettyFormatting makes the response easier to view
                // with web browser developer tools.  It just adds whitespace and newlines to the response,
                // so production environments would typically leave this turned off.
                output.PrettyFormatting = true;

                // The whole body of CZML must be wrapped in a JSON array, opened here.
                output.WriteStartSequence();

                // The first packet (JSON object) of CZML must be the document packet.
                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("document");
                    entity.WriteVersion("1.0");
                }

                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("canavitem");
                    using (var pos = entity.OpenPositionProperty())
                    {
                        pos.WriteCartesian(CesiumDataManager.GetBaseCartesian());
                    }
                    using (var point = entity.OpenPointProperty())
                    {
                        point.WriteColorProperty(Color.Aqua);
                        point.WritePixelSizeProperty(10.0);
                    }
                }

                rocketData = new RocketTrajectoryData();

                var entities = rocketData.GetStandardRocketTrajectoryData();


                var cartList = new List <Cartesian>();
                var dateList = new List <JulianDate>();

                var now = DateTime.Now;

                for (int i = 0; i < entities.data[2].x.Count; i++)
                {
                    var cartesian = CesiumDataManager.GenerateCartesian(entities.data[2].x[i], entities.data[2].y[i]);
                    cartList.Add(cartesian);
                    var julDate = new JulianDate(now + TimeSpan.FromSeconds(i * 2));
                    dateList.Add(julDate);
                }

                using (var thisEntity = cesiumWriter.OpenPacket(output))
                {
                    thisEntity.WriteId("testpath");
                    thisEntity.WriteDescriptionProperty("rocket launch path");
                    using (var position = thisEntity.OpenPositionProperty())
                    {
                        position.WriteCartesian(dateList, cartList);
                        position.WriteReferenceFrame("#referenceitem");
                    }

                    //using (var model = thisEntity.OpenModelProperty())
                    //{
                    //    model.WriteGltfProperty(new Uri("http://localhost:56332/Models/CesiumAir/Cesium_Air.gltf"),CesiumResourceBehavior.Embed);
                    //}

                    using (var path = thisEntity.OpenPathProperty())
                    {
                        using (var material = path.OpenMaterialProperty())
                        {
                            using (var outline = material.OpenSolidColorProperty())
                            {
                                using (var colour = outline.OpenColorProperty())
                                {
                                    colour.WriteRgba(Color.DarkSeaGreen);
                                }
                            }
                        }
                        path.WriteWidthProperty(8);
                        path.WriteLeadTimeProperty(10);
                        path.WriteTrailTimeProperty(1000);
                        path.WriteResolutionProperty(5);
                    }
                }



                // Close the JSON array that wraps the entire CZML document.
                output.WriteEndSequence();
            }
        }