Example #1
0
        public PacketCesiumWriter OpenPacket([NotNull] CesiumOutputStream output)
        {
            PacketCesiumWriter packetWriter = m_packetWriter.Value;

            packetWriter.Open(output);
            return(packetWriter);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CzmlDocument"/> class.
 /// </summary>
 public CzmlDocument(TextWriter outputWriter)
 {
     m_output = new CesiumOutputStream(outputWriter);
     m_writer = new CesiumStreamWriter();
     m_imageResolver = new CachingCesiumUrlResolver(int.MaxValue);
     Namespace = "";
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CzmlDocument"/> class.
 /// </summary>
 public CzmlDocument(TextWriter outputWriter)
 {
     m_output = new CesiumOutputStream(outputWriter);
     m_writer = new CesiumStreamWriter();
     m_imageResolver = new CachingCesiumUrlResolver(int.MaxValue);
     NamespaceDeclarations = new Dictionary<string, XNamespace>();
     Namespace = "";
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CzmlDocument"/> class.
 /// </summary>
 /// <param name="imageMap">The image map.</param>
 public CzmlDocument(Dictionary<string, string> imageMap)
 {
     this.ImageMap = imageMap;
     m_sw = new StringWriter();
     m_output = new CesiumOutputStream(m_sw);
     m_writer = new CesiumStreamWriter();
     Namespace = "";
 }
        public HttpResponseMessage Get()
        {
            StringWriter sw = new StringWriter();

            CesiumOutputStream output = new CesiumOutputStream(sw);
            CesiumStreamWriter czmlWriter = new CesiumStreamWriter();

            output.WriteStartSequence();

            using (var entity = czmlWriter.OpenPacket(output))
            {
                entity.WriteId("document");
                entity.WriteVersion("1.0");
            }

            for (int lat = 0; lat < 60; lat = lat + 5)
            {
                for (int lon = 0; lon < 100; lon = lon + 5)
                {
                    using (var entity = czmlWriter.OpenPacket(output))
                    {
                        entity.WriteId("facility_" + lat.ToString() + "_" + lon.ToString());
                        entity.WriteName("facility_" + lat.ToString() + "_" + lon.ToString());
                        entity.WritePositionPropertyCartographicDegrees(new Cartographic(lon, lat, 100));

                        using (var billboard = entity.OpenBillboardProperty())
                        {
                            Uri uri = new Uri("http://localhost:64225/Data/Facility.png");
                            CesiumResource resource = new CesiumResource(uri, CesiumResourceBehavior.LinkTo);
                            billboard.WriteImageProperty(resource);
                        }

                        using (var label = entity.OpenLabelProperty())
                        {
                            label.WriteTextProperty("facility_" + lat.ToString() + "_" + lon.ToString());
                            label.WriteHorizontalOriginProperty(CesiumHorizontalOrigin.Left);
                            label.WriteVerticalOriginProperty(CesiumVerticalOrigin.Bottom);
                        }

                        using (var model = entity.OpenModelProperty())
                        {
                            model.WriteGltfProperty(new CesiumResource(
                                new Uri("http://localhost:64225/Data/Cesium_Man.bgltf"),
                                CesiumResourceBehavior.LinkTo));
                            model.WriteScaleProperty(500000);
                        }
                    }
                }
            }

            output.WriteEndSequence();

            var response = Request.CreateResponse();
            response.StatusCode = HttpStatusCode.OK;
            response.Content = new StringContent(sw.ToString(), System.Text.Encoding.UTF8, "application/json");

            return response;
        }
 public void SetUp()
 {
     m_sw = new StringWriter();
     m_output = new CesiumOutputStream(m_sw);
     m_writer = new CesiumStreamWriter();
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CzmlDocument"/> class.
 /// </summary>
 public CzmlDocument(TextWriter outputWriter)
 {
     m_output = new CesiumOutputStream(outputWriter);
     m_writer = new CesiumStreamWriter();
 }
 /// <summary>
 /// Starts a new <topic name="Cesium">Cesium</topic> packet on the given stream.
 /// </summary>
 /// <param name="output">The stream to which to write the packet.</param>
 /// <returns>The packet writer.</returns>
 public PacketCesiumWriter OpenPacket(CesiumOutputStream output)
 {
     PacketCesiumWriter packetWriter = m_packetWriter.Value;
     packetWriter.Open(output);
     return packetWriter;
 }
 public void SetUp()
 {
     m_stringWriter = new StringWriter();
     m_outputStream = new CesiumOutputStream(m_stringWriter);
 }
Example #10
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.
                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");
                }

                // 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.ToString("0") + " degrees</td></tr>" +
                                    "<tr><td>Latitude</td><td>" + lat.ToString("0") + " degrees</td></tr>" +
                                    "</tbody></table>");
                            }
                        }
                    }
                }

                // Close the JSON array that wraps the entire CZML document.
                output.WriteEndSequence();
            }
        }
        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("]");
            }
        }