Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Point"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="document">The document.</param>
        /// <param name="placemark">The placemark.</param>
        public Point(XElement element, CzmlDocument document, XElement placemark)
            : base(document, placemark)
        {
            m_element = element;
            XElement extrudeElement = m_element.Element(Document.Namespace + "extrude");
            if (extrudeElement != null && extrudeElement.Value == "1")
            {
                m_extrude = true;
            }

            string coordinates = m_element.Element(Document.Namespace + "coordinates").Value.Trim();
            string[] coord = Regex.Split(coordinates, @"[,\s]+", RegexOptions.Multiline);
            XElement altitudeMode = m_element.Element(Document.Namespace + "altitudeMode");
            if (altitudeMode != null && altitudeMode.Value == "clampToGround")
            {
                m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, double.Parse(coord[1]) * Constants.RadiansPerDegree, 0);
                Debug.Assert(coord.Length == 2 || coord.Length == 3);
            }
            else
            {
                if (coord.Length == 1)
                {
                    m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, 0.0, 0.0);
                }
                else if (coord.Length == 2)
                {
                    m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, double.Parse(coord[1]) * Constants.RadiansPerDegree, 0.0);
                }
                else
                {
                    m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, double.Parse(coord[1]) * Constants.RadiansPerDegree, double.Parse(coord[2]));
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Placemark"/> class.
 /// </summary>
 /// <param name="placemark">The placemark.</param>
 /// <param name="document">The document.</param>
 public Placemark(XElement placemark, CzmlDocument document)
 {
     XNamespace gxNs = null;
     XName gxNsTrack = null;
     XName gxNsMultiTrack = null;
     XName gxNsInterpolate = null;
     if (document.NamespaceDeclarations.TryGetValue(Utility.GxPrefix, out gxNs))
     {
         gxNsTrack = gxNs + "Track";
         gxNsMultiTrack = gxNs + "MultiTrack";
         gxNsInterpolate = gxNs + "interpolate";
     }
     m_geometries = placemark.Descendants().Where(
         o =>
         {
             if ((o.Name == document.Namespace + "Point") || 
                 (o.Name == document.Namespace + "Polygon") || 
                 (o.Name == document.Namespace + "LineString") ||
                 (gxNs != null && ((o.Name == gxNsTrack && gxNsMultiTrack != o.Parent.Name) ||
                     (o.Name == gxNsTrack && gxNsMultiTrack == o.Parent.Name && (o.Parent.Element(gxNsInterpolate) == null || o.Parent.Element(gxNsInterpolate).Value == "0")) ||
                     (o.Name == gxNsTrack && gxNsMultiTrack == o.Parent.Name && (o.Parent.Element(gxNsInterpolate) == null || o.Parent.Element(gxNsInterpolate).Value == "0")) ||
                     (o.Name == gxNsMultiTrack && (o.Element(gxNsInterpolate) != null && Utility.ParseBoolean(o.Element(gxNsInterpolate)))))))
             {
                 return true;
             }
             return false;
         }
         ).Select(o => GeometryFactory.Create(o, document, placemark));
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Placemark"/> class.
        /// </summary>
        /// <param name="placemark">The placemark.</param>
        /// <param name="document">The document.</param>
        public Placemark(XElement placemark, CzmlDocument document)
        {
            XNamespace gxNs            = null;
            XName      gxNsTrack       = null;
            XName      gxNsMultiTrack  = null;
            XName      gxNsInterpolate = null;

            if (document.NamespaceDeclarations.TryGetValue(Utility.GxPrefix, out gxNs))
            {
                gxNsTrack       = gxNs + "Track";
                gxNsMultiTrack  = gxNs + "MultiTrack";
                gxNsInterpolate = gxNs + "interpolate";
            }
            m_geometries = placemark.Descendants().Where(
                o =>
            {
                if ((o.Name == document.Namespace + "Point") ||
                    (o.Name == document.Namespace + "Polygon") ||
                    (o.Name == document.Namespace + "LineString") ||
                    (gxNs != null && ((o.Name == gxNsTrack && gxNsMultiTrack != o.Parent.Name) ||
                                      (o.Name == gxNsTrack && gxNsMultiTrack == o.Parent.Name && (o.Parent.Element(gxNsInterpolate) == null || o.Parent.Element(gxNsInterpolate).Value == "0")) ||
                                      (o.Name == gxNsTrack && gxNsMultiTrack == o.Parent.Name && (o.Parent.Element(gxNsInterpolate) == null || o.Parent.Element(gxNsInterpolate).Value == "0")) ||
                                      (o.Name == gxNsMultiTrack && (o.Element(gxNsInterpolate) != null && Utility.ParseBoolean(o.Element(gxNsInterpolate)))))))
                {
                    return(true);
                }
                return(false);
            }
                ).Select(o => GeometryFactory.Create(o, document, placemark));
        }
Пример #4
0
        /// <summary>
        /// Converts a kmz file to CZML.
        /// </summary>
        /// <param name="kmzContents">The content of the kmz file.</param>
        /// <param name="document">The czml document.</param>
        public static void KmzToCesiumLanguage(byte[] kmzContents, CzmlDocument document)
        {
            List<byte[]> documents = new List<byte[]>();
            using (ZipFile zip = ZipFile.Read(new MemoryStream(kmzContents)))
            {
                foreach(ZipEntry entry in zip)
                {
                    MemoryStream memoryStream = new MemoryStream();
                    entry.Extract(memoryStream);
                    memoryStream.Position = 0;
                    if (entry.FileName.Contains(".kml"))
                    {
                        long size = memoryStream.Length;
                        byte[] data = new byte[size];
                        memoryStream.Read(data, 0, data.Length);
                        documents.Add(data);
                    }

                    if (entry.FileName.Contains(".jpg") || entry.FileName.Contains(".png") || entry.FileName.Contains(".gif"))
                    {
                        if (!document.ImageMap.ContainsKey(entry.FileName))
                        {
                            document.ImageMap.Add(entry.FileName, CesiumFormattingHelper.ImageToDataUrl(Image.FromStream(memoryStream)));
                        }
                    }
                }
            }
            document.CesiumOutputStream.WriteStartSequence();
            foreach (byte[] kmlContents in documents)
            {
                Convert(kmlContents, document);
            }
            document.CesiumOutputStream.WriteEndSequence();
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GxTrack"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 /// <param name="altitudeMode">The altitude mode.</param>
 public GxTrack(XElement element, CzmlDocument document, XElement placemark, string altitudeMode) : this(element, document, placemark)
 {
     if (altitudeMode != string.Empty)
     {
         m_altitudeMode = altitudeMode;
     }
 }
Пример #6
0
        static public Geometry Create(XElement element, CzmlDocument document, XElement placemark)
        {
            if (element.Name == document.Namespace + "Point")
            {
                return(new Point(element, document, placemark));
            }
            if (element.Name == document.Namespace + "Polygon")
            {
                return(new Polygon(element, document, placemark));
            }
            if (element.Name == document.Namespace + "LineString")
            {
                return(new LineString(element, document, placemark));
            }
            XNamespace xnamespace = null;;

            if (document.NamespaceDeclarations.TryGetValue(Utility.GxPrefix, out xnamespace))
            {
                if (element.Name == xnamespace + "MultiTrack")
                {
                    return(new GxMultiTrack(element, document, placemark));
                }
                if (element.Name == xnamespace + "Track")
                {
                    return(new GxTrack(element, document, placemark));
                }
            }
            throw new NotImplementedException();
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GxTrack"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 /// <param name="altitudeMode">The altitude mode.</param>
 public GxTrack(XElement element, CzmlDocument document, XElement placemark, string altitudeMode):this(element, document, placemark)
 {
     if (altitudeMode != string.Empty)
     {
         m_altitudeMode = altitudeMode;
     }
 }
Пример #8
0
        private static void Convert(TextReader inputReader, CzmlDocument document)
        {
            XDocument kmlDocument = XDocument.Load(inputReader);

            document.Namespace = kmlDocument.Root.GetDefaultNamespace();

            var namespaceDeclarations = kmlDocument.Root.Attributes()
                                        .Where(a => a.IsNamespaceDeclaration)
                                        .GroupBy(a => a.Name.Namespace == XNamespace.None ? String.Empty : a.Name.LocalName, a => XNamespace.Get(a.Value))
                                        .ToDictionary(g => g.Key, g => g.First());

            foreach (var ns in namespaceDeclarations)
            {
                document.NamespaceDeclarations.Add(ns.Key, ns.Value);
            }

            var features = kmlDocument.Descendants()
                           .Where(o => o.Name == document.Namespace + "Placemark" || o.Name == document.Namespace + "GroundOverlay")
                           .Select(o => FeatureFactory.Create(o, document));

            foreach (var feature in features)
            {
                feature.WritePacket();
            }
        }
Пример #9
0
 static public Feature Create(XElement feature, CzmlDocument document)
 {
     if (feature.Name == document.Namespace + "Placemark")
         return new Placemark(feature, document);
     if (feature.Name == document.Namespace + "GroundOverlay")
         return new GroundOverlay(feature, document);
     throw new NotImplementedException();
 }
Пример #10
0
 static public Geometry Create(XElement element, CzmlDocument document, XElement placemark)
 {
     if (element.Name == document.Namespace + "Point")
         return new Point(element, document, placemark);
     if (element.Name == document.Namespace + "Polygon")
         return new Polygon(element, document, placemark);
     if (element.Name == document.Namespace + "LineString")
         return new LineString(element, document, placemark);
     throw new NotImplementedException();
 }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Polygon"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 public Polygon(XElement element, CzmlDocument document, XElement placemark)
     : base(document, placemark)
 {
     m_element = element;
     XElement altitudeMode = m_element.Element(Document.Namespace + "altitudeMode");
     if (altitudeMode != null)
     {
         m_altitudeMode = altitudeMode.Value;
     }
     
 }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Polygon"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="document">The document.</param>
        /// <param name="placemark">The placemark.</param>
        public Polygon(XElement element, CzmlDocument document, XElement placemark)
            : base(document, placemark)
        {
            m_element = element;
            XElement altitudeMode = m_element.Element(Document.Namespace + "altitudeMode");

            if (altitudeMode != null)
            {
                m_altitudeMode = altitudeMode.Value;
            }
        }
Пример #13
0
        /// <summary>
        /// Converts a KML document to CZML.
        /// </summary>
        /// <param name="inputReader">A reader for a KML document.</param>
        /// <param name="outputWriter">A writer that will receive the converted CZML document.</param>
        /// <param name="prettyFormatting">If true, produces larger, more readable.  False by default.</param>
        public static void KmlToCesiumLanguage(TextReader inputReader,
                                               TextWriter outputWriter,
                                               bool prettyFormatting = false)
        {
            CzmlDocument document = new CzmlDocument(outputWriter);

            document.CesiumOutputStream.PrettyFormatting = prettyFormatting;

            document.CesiumOutputStream.WriteStartSequence();
            Convert(inputReader, document);
            document.CesiumOutputStream.WriteEndSequence();
        }
Пример #14
0
 static public Feature Create(XElement feature, CzmlDocument document)
 {
     if (feature.Name == document.Namespace + "Placemark")
     {
         return(new Placemark(feature, document));
     }
     if (feature.Name == document.Namespace + "GroundOverlay")
     {
         return(new GroundOverlay(feature, document));
     }
     throw new NotImplementedException();
 }
Пример #15
0
        /// <summary>
        /// Converts a KML document to CZML.
        /// </summary>
        /// <param name="inputReader">A reader for a KML document.</param>
        /// <param name="outputWriter">A writer that will receive the converted CZML document.</param>
        /// <param name="prettyFormatting">If true, produces larger, more readable.  False by default.</param>
        public static void KmlToCesiumLanguage(TextReader inputReader,
                                               TextWriter outputWriter,
                                               bool prettyFormatting = false)
        {
            CzmlDocument document = new CzmlDocument(outputWriter);

            document.CesiumOutputStream.PrettyFormatting = prettyFormatting;

            document.CesiumOutputStream.WriteStartSequence();
            Convert(inputReader, document);
            document.CesiumOutputStream.WriteEndSequence();
        }
Пример #16
0
 private static void Convert(byte[] kmlContents, CzmlDocument document)
 {
     using (MemoryStream stream = new MemoryStream(kmlContents))
     {
         XDocument kmlDocument = XDocument.Load(stream);
         document.Namespace = kmlDocument.Root.GetDefaultNamespace();
         var placemarks = kmlDocument.Descendants(document.Namespace + "Placemark").Select(o => new Placemark(o, document));
         foreach (var placemark in placemarks)
         {
             placemark.Write();
         }
     }
 }
Пример #17
0
        public void LineStringWithoutAltitudeProducesCartographicWithZeroHeight()
        {
            CzmlDocument document = new CzmlDocument();
            var placemark = new XElement("Placemark",
                                new XElement("LineString",
                                    new XElement("altitudeMode", "absolute"),
                                    new XElement("coordinates", "-68.736144,37.34996200000001 -68.73866678120611,37.3482063896964")));

            var lineString = new LineString(placemark.Element("LineString"), document, placemark);
            lineString.WritePacket();
            string result = document.StringWriter.ToString();
            Assert.That(result.Contains("\"vertexPositions\":{\"cartographicRadians\":[-1.199672027924945,0.6518798123947666,0.0,-1.1997160587632991,0.6518491712145866,0.0]}"));
        }
Пример #18
0
 public void PolygonClampToGroundProducesCartographicsWithZeroHeight()
 {
     XElement placemark = new XElement("Placemark",
                                         new XElement("name", "Access Polygon"),
                                         new XElement("Polygon",
                                             new XElement("altitudeMode", "clampToGround"),
                                             new XElement("outerBoundaryIs",
                                                 new XElement("LinearRing",
                                                     new XElement("coordinates", "-74.42333000000001,39.364163,1 -74.1855216770938,33.4296610235422,105622.226606304")))));
     CzmlDocument document = new CzmlDocument();
     document.Namespace = "";
     var polygon = new Polygon(placemark.Element("Polygon"), document, placemark);
     polygon.WritePacket();
     string result = document.StringWriter.ToString();
     Assert.That(result.Contains("\"vertexPositions\":{\"cartographicRadians\":[-1.2989321487982717,0.6870342516417286,0.0,-1.2947816105749124,0.583457652686429,0.0]}"));
 }
Пример #19
0
        public void LineStringWithStyleProducesPolylineGraphics()
        {
            CzmlDocument document = new CzmlDocument();
            var placemark = new XElement("Placemark",
                                new XElement("Style", 
                                    new XElement("LineStyle",
                                        new XElement("color", "ffffffff"),
                                        new XElement("width", "2"))),
                                new XElement("LineString",
                                    new XElement("altitudeMode", "absolute"),
                                    new XElement("coordinates", "-68.736144,37.34996200000001,105045.668999999 -68.73866678120611,37.3482063896964,105041.867978398")));

            var lineString = new LineString(placemark.Element("LineString"), document, placemark);
            lineString.WritePacket();
            string result = document.StringWriter.ToString();
            Assert.That(result.Contains("\"polyline\":{\"color\":{\"rgba\":[255,255,255,255]},\"width\":2.0,\"outlineWidth\":0.0}"));
        }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GxTrack"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 public GxTrack(XElement element, CzmlDocument document, XElement placemark)
     : base(document, placemark)
 {
     m_element = element;
     m_document = document;
     m_altitudeMode = "clampToGround";
     XElement altitudeMode = m_element.Element(m_document.Namespace + "altitudeMode");
     if (altitudeMode != null)
     {
         m_altitudeMode = altitudeMode.Value;
     }
     //ignoring gx:angles for now;
     //ignoring model for now;
     //and extended data. will be useful when we have popup support in czml
     m_when = m_element.Elements(m_document.Namespace+"when");
     m_positions = m_element.Elements( document.NamespaceDeclarations[Utility.GxPrefix] +  "coord");
 }
Пример #21
0
 public void PolygonWithTimeSpanProducesAvailability()
 {
     XElement placemark = new XElement("Placemark",
                             new XElement("TimeSpan",
                                 new XElement("begin", "2007-12-06T16:38:22.920"),
                                 new XElement("end", "2007-12-06T16:38:32.920")),
                             new XElement("Polygon",
                                 new XElement("altitudeMode", "absolute"),
                                 new XElement("outerBoundaryIs",
                                     new XElement("LinearRing",
                                         new XElement("coordinates", "-74.42333000000001,39.364163,1 -74.1855216770938,33.4296610235422,105622.226606304")))));
     CzmlDocument document = new CzmlDocument();
     var polygon = new Polygon(placemark.Element("Polygon"), document, placemark);
     polygon.WritePacket();
     string result = document.StringWriter.ToString();
     Assert.That(result.Contains("\"availability\":\"2007-12-06T16:38:22.9199999999983Z/2007-12-06T16:38:32.9199999999983Z\""));
 }
Пример #22
0
        public void LineStringTimeSpanProducesAvailability()
        {
            CzmlDocument document = new CzmlDocument();
            var placemark = new XElement("Placemark",
                                new XElement("name", "STS-122"),
                                new XElement("TimeSpan",
                                    new XElement("begin", "2007-12-06T16:31"),
                                    new XElement("end", "2007-12-06T16:40:18.040")),
                                new XElement("LineString",
                                    new XElement("altitudeMode", "absolute"),
                                    new XElement("coordinates", "-68.736144,37.34996200000001,105045.668999999 -68.73866678120611,37.3482063896964,105041.867978398")));

            var lineString = new LineString(placemark.Element("LineString"), document, placemark);
            lineString.WritePacket();
            string result = document.StringWriter.ToString();
            Assert.That(result.Contains("\"availability\":\"2007-12-06T16:31:00Z/2007-12-06T16:40:18.0400000000009Z\""));
        }
Пример #23
0
 public void PolygonWithPolyStyleProducesPolygonGraphics()
 {
     XElement placemark = new XElement("Placemark",
                             new XElement("Style",
                                 new XElement("PolyStyle",
                                     new XElement("color", "ffffffff"))),
                             new XElement("Polygon",
                                 new XElement("altitudeMode", "absolute"),
                                 new XElement("outerBoundaryIs",
                                     new XElement("LinearRing",
                                         new XElement("coordinates", "-74.42333000000001,39.364163,1 -74.1855216770938,33.4296610235422,105622.226606304")))));
     CzmlDocument document = new CzmlDocument();
     document.Namespace = "";
     var polygon = new Polygon(placemark.Element("Polygon"), document, placemark);
     polygon.WritePacket();
     string result = document.StringWriter.ToString();
     Assert.That(result.Contains("\"polygon\":{\"material\":{\"solidColor\":{\"color\":{\"rgba\":[255,255,255,255]}}}}"));
 }
Пример #24
0
 static public Geometry Create(XElement element, CzmlDocument document, XElement placemark)
 {
     if (element.Name == document.Namespace + "Point")
         return new Point(element, document, placemark);
     if (element.Name == document.Namespace + "Polygon")
         return new Polygon(element, document, placemark);
     if (element.Name == document.Namespace + "LineString")
         return new LineString(element, document, placemark);
     XNamespace xnamespace = null; ;
     if (document.NamespaceDeclarations.TryGetValue(Utility.GxPrefix, out xnamespace))
     {
         if (element.Name == xnamespace + "MultiTrack")
             return new GxMultiTrack(element, document, placemark);
         if (element.Name == xnamespace + "Track")
             return new GxTrack(element, document, placemark);
     }
     throw new NotImplementedException();
 }
Пример #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GxTrack"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="document">The document.</param>
        /// <param name="placemark">The placemark.</param>
        public GxTrack(XElement element, CzmlDocument document, XElement placemark)
            : base(document, placemark)
        {
            m_element      = element;
            m_document     = document;
            m_altitudeMode = "clampToGround";
            XElement altitudeMode = m_element.Element(m_document.Namespace + "altitudeMode");

            if (altitudeMode != null)
            {
                m_altitudeMode = altitudeMode.Value;
            }
            //ignoring gx:angles for now;
            //ignoring model for now;
            //and extended data. will be useful when we have popup support in czml
            m_when      = m_element.Elements(m_document.Namespace + "when");
            m_positions = m_element.Elements(document.NamespaceDeclarations[Utility.GxPrefix] + "coord");
        }
Пример #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GxMultiTrack"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="document">The document.</param>
        /// <param name="placemark">The placemark.</param>
        public GxMultiTrack(XElement element, CzmlDocument document, XElement placemark)
            : base(document, placemark)
        {
            m_element = element;
            m_gxTracks = m_element.Elements(document.NamespaceDeclarations[Utility.GxPrefix] +  "Track").Select(o=> new GxTrack(o, document, placemark));
            m_document = document;
            XElement gxInterpolate = m_element.Element( document.NamespaceDeclarations[Utility.GxPrefix] +  "interpolate");
            m_interpolate = false;
            if (gxInterpolate != null)
            {
                m_interpolate = Utility.ParseBoolean(gxInterpolate);
            }
            m_altitudeMode = "clampToGround";
            XElement altitudeMode = m_element.Element(m_document.Namespace + "altitudeMode");
            if (altitudeMode != null)
            {
                m_altitudeMode = altitudeMode.Value;
            }

        }
Пример #27
0
        /// <summary>
        /// Converts a KMZ file to CZML.
        /// </summary>
        /// <param name="inputStream">A stream for a KMZ file.</param>
        /// <param name="outputWriter">A writer that will receive the converted CZML document.</param>
        /// <param name="prettyFormatting">If true, produces larger, more readable.  False by default.</param>
        public static void KmzToCesiumLanguage(Stream inputStream,
                                               TextWriter outputWriter,
                                               bool prettyFormatting = false)
        {
            CzmlDocument document = new CzmlDocument(outputWriter);

            document.CesiumOutputStream.PrettyFormatting = prettyFormatting;

            document.CesiumOutputStream.WriteStartSequence();

            using (ZipFile zipFile = ZipFile.Read(inputStream))
            {
                foreach (ZipEntry entry in zipFile)
                {
                    string fileName = entry.FileName;
                    CesiumImageFormat? imageFormat = InferImageFormat(fileName);

                    if (imageFormat != null && !document.ImageResolver.ContainsUrl(fileName))
                    {
                        using (Stream stream = entry.OpenReader())
                        {
                            string dataUrl = CesiumFormattingHelper.ImageToDataUri(stream, imageFormat.Value);
                            document.ImageResolver.AddUrl(fileName, dataUrl);
                        }
                    }
                }

                foreach (ZipEntry entry in zipFile)
                {
                    string extension = Path.GetExtension(entry.FileName);
                    if (".kml".Equals(extension, StringComparison.OrdinalIgnoreCase))
                    {
                        using (Stream stream = entry.OpenReader())
                        using (StreamReader streamReader = new StreamReader(stream))
                            Convert(streamReader, document);
                    }
                }
            }

            document.CesiumOutputStream.WriteEndSequence();
        }
Пример #28
0
        /// <summary>
        /// Converts a KMZ file to CZML.
        /// </summary>
        /// <param name="inputStream">A stream for a KMZ file.</param>
        /// <param name="outputWriter">A writer that will receive the converted CZML document.</param>
        /// <param name="prettyFormatting">If true, produces larger, more readable.  False by default.</param>
        public static void KmzToCesiumLanguage(Stream inputStream,
                                               TextWriter outputWriter,
                                               bool prettyFormatting = false)
        {
            CzmlDocument document = new CzmlDocument(outputWriter);

            document.CesiumOutputStream.PrettyFormatting = prettyFormatting;

            document.CesiumOutputStream.WriteStartSequence();

            using (ZipFile zipFile = ZipFile.Read(inputStream))
            {
                foreach (ZipEntry entry in zipFile)
                {
                    string            fileName    = entry.FileName;
                    CesiumImageFormat?imageFormat = InferImageFormat(fileName);

                    if (imageFormat != null && !document.ImageResolver.ContainsUrl(fileName))
                    {
                        using (Stream stream = entry.OpenReader())
                        {
                            string dataUrl = CesiumFormattingHelper.ImageToDataUri(stream, imageFormat.Value);
                            document.ImageResolver.AddUrl(fileName, dataUrl);
                        }
                    }
                }

                foreach (ZipEntry entry in zipFile)
                {
                    string extension = Path.GetExtension(entry.FileName);
                    if (".kml".Equals(extension, StringComparison.OrdinalIgnoreCase))
                    {
                        using (Stream stream = entry.OpenReader())
                            using (StreamReader streamReader = new StreamReader(stream))
                                Convert(streamReader, document);
                    }
                }
            }

            document.CesiumOutputStream.WriteEndSequence();
        }
Пример #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GxMultiTrack"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="document">The document.</param>
        /// <param name="placemark">The placemark.</param>
        public GxMultiTrack(XElement element, CzmlDocument document, XElement placemark)
            : base(document, placemark)
        {
            m_element      = element;
            m_altitudeMode = "clampToGround";
            m_document     = document;
            XElement altitudeMode = m_element.Element(m_document.Namespace + "altitudeMode");

            if (altitudeMode != null)
            {
                m_altitudeMode = altitudeMode.Value;
            }
            m_gxTracks = m_element.Elements(document.NamespaceDeclarations[Utility.GxPrefix] + "Track").Select(o => new GxTrack(o, document, placemark, m_altitudeMode));

            XElement gxInterpolate = m_element.Element(document.NamespaceDeclarations[Utility.GxPrefix] + "interpolate");

            m_interpolate = false;
            if (gxInterpolate != null)
            {
                m_interpolate = Utility.ParseBoolean(gxInterpolate);
            }
        }
Пример #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Point"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="document">The document.</param>
        /// <param name="placemark">The placemark.</param>
        public Point(XElement element, CzmlDocument document, XElement placemark)
            : base(document, placemark)
        {
            m_element = element;
            XElement extrudeElement = m_element.Element(Document.Namespace + "extrude");

            if (extrudeElement != null && extrudeElement.Value == "1")
            {
                m_extrude = true;
            }

            string coordinates = m_element.Element(Document.Namespace + "coordinates").Value.Trim();

            string[] coord        = Regex.Split(coordinates, @"[,\s]+", RegexOptions.Multiline);
            XElement altitudeMode = m_element.Element(Document.Namespace + "altitudeMode");

            if (altitudeMode != null && altitudeMode.Value == "clampToGround")
            {
                m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, double.Parse(coord[1]) * Constants.RadiansPerDegree, 0);
                Debug.Assert(coord.Length == 2 || coord.Length == 3);
            }
            else
            {
                if (coord.Length == 1)
                {
                    m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, 0.0, 0.0);
                }
                else if (coord.Length == 2)
                {
                    m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, double.Parse(coord[1]) * Constants.RadiansPerDegree, 0.0);
                }
                else
                {
                    m_position = new Cartographic(double.Parse(coord[0]) * Constants.RadiansPerDegree, double.Parse(coord[1]) * Constants.RadiansPerDegree, double.Parse(coord[2]));
                }
            }
        }
Пример #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Polygon"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 public Polygon(XElement element, CzmlDocument document, XElement placemark)
     : base(document, placemark)
 {
     m_element = element;
 }
Пример #32
0
 /// <summary>
 /// Converts an kml document to CZML.
 /// </summary>
 /// <param name="kmlContents">The KML contents.</param>
 /// <param name="document">The czml document.</param>
 public static void KmlToCesiumLanguage(byte[] kmlContents, CzmlDocument document)
 {
     document.CesiumOutputStream.WriteStartSequence();
     Convert(kmlContents, document);
     document.CesiumOutputStream.WriteEndSequence();
 }
Пример #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineString"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 public LineString(XElement element, CzmlDocument document, XElement placemark)
     : base(document, placemark)
 {
     m_element = element;
 }
Пример #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Geometry"/> class.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 protected Geometry(CzmlDocument document, XElement placemark)
 {
     m_document = document;
     m_placemark = placemark;
 }
Пример #35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroundOverlay"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 public GroundOverlay(XElement element, CzmlDocument document)
 {
     m_element  = element;
     m_document = document;
 }
Пример #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Placemark"/> class.
 /// </summary>
 /// <param name="placemark">The placemark.</param>
 /// <param name="document">The document.</param>
 public Placemark(XElement placemark, CzmlDocument document)
 {
     m_geometries = placemark.Descendants().Where(o => o.Name == document.Namespace + "Point" || o.Name == document.Namespace + "Polygon" || o.Name == document.Namespace + "LineString").Select(o => GeometryFactory.Create(o, document, placemark));
 }
Пример #37
0
 public void SetUp()
 {
     m_stringWriter = new StringWriter();
     m_document = new CzmlDocument(m_stringWriter);
 }
Пример #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Geometry"/> class.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 protected Geometry(CzmlDocument document, XElement placemark)
 {
     m_document  = document;
     m_placemark = placemark;
 }
Пример #39
0
 public void SetUp()
 {
     m_stringWriter = new StringWriter();
     m_document = new CzmlDocument(m_stringWriter);
     m_document.NamespaceDeclarations["gx"] = m_gxNamespace;
 }
Пример #40
0
 private static void Convert(TextReader inputReader, CzmlDocument document)
 {
     XDocument kmlDocument = XDocument.Load(inputReader);
     document.Namespace = kmlDocument.Root.GetDefaultNamespace();
     var features = kmlDocument.Descendants()
         .Where(o => o.Name == document.Namespace + "Placemark" || o.Name == document.Namespace + "GroundOverlay")
         .Select(o => FeatureFactory.Create(o, document));
     foreach (var feature in features)
     {
         feature.WritePacket();
     }
 }
Пример #41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineString"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 /// <param name="placemark">The placemark.</param>
 public LineString(XElement element, CzmlDocument document, XElement placemark)
     : base(document, placemark)
 {
     m_element = element;
 }
Пример #42
0
 public void KmzSandbox()
 {
     CzmlDocument document = new CzmlDocument();
     document.CesiumOutputStream.PrettyFormatting = true;
     KmlConverter.KmzToCesiumLanguage(File.ReadAllBytes(@"KmlDocs\I&W KML.kmz"), document);
     string czml = document.StringWriter.ToString();
     Console.WriteLine(czml);
 }
Пример #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroundOverlay"/> class.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="document">The document.</param>
 public GroundOverlay(XElement element, CzmlDocument document)
 {
     m_element = element;
     m_document = document;
 }
Пример #44
0
 public TestPoint()
 {
     m_document = new CzmlDocument();
 }