Ejemplo n.º 1
0
            private void Parse(Stream stream)
            {
                var doc = new XmlDocument();

                doc.Load(stream);
                var nsmgr = new XmlNamespaceManager(doc.NameTable);

                var ns = "";

                if (doc.DocumentElement != null && doc.DocumentElement.Attributes["xmlns"] != null)
                {
                    nsmgr.AddNamespace("ns", doc.DocumentElement.Attributes["xmlns"].Value);
                    ns = "ns:";
                }

                var groundOverlays = doc.SelectNodes(string.Format("//{0}GroundOverlay[1]", ns), nsmgr);

                if (groundOverlays != null && groundOverlays.Count > 0)
                {
                    var iconNodes = groundOverlays[0].SelectNodes(string.Format("{0}Icon/{0}href", ns), nsmgr);
                    if (iconNodes != null && iconNodes.Count > 0)
                    {
                        ImageFileName = iconNodes[0].InnerText;
                    }

                    var latLonBoxNodes = groundOverlays[0].SelectNodes(string.Format("{0}LatLonBox", ns), nsmgr);
                    if (latLonBoxNodes != null && latLonBoxNodes.Count > 0)
                    {
                        LongLatBox = new LongLatBox()
                        {
                            North =
                                Convert.ToDouble(latLonBoxNodes[0].SelectSingleNode(string.Format("{0}north", ns), nsmgr).InnerText,
                                                 CultureInfo.InvariantCulture),
                            South =
                                Convert.ToDouble(latLonBoxNodes[0].SelectSingleNode(string.Format("{0}south", ns), nsmgr).InnerText,
                                                 CultureInfo.InvariantCulture),
                            West =
                                Convert.ToDouble(latLonBoxNodes[0].SelectSingleNode(string.Format("{0}west", ns), nsmgr).InnerText,
                                                 CultureInfo.InvariantCulture),
                            East =
                                Convert.ToDouble(latLonBoxNodes[0].SelectSingleNode(string.Format("{0}east", ns), nsmgr).InnerText,
                                                 CultureInfo.InvariantCulture),
                            Rotation =
                                Convert.ToDouble(latLonBoxNodes[0].SelectSingleNode(string.Format("{0}rotation", ns), nsmgr).InnerText,
                                                 CultureInfo.InvariantCulture) / 180.0 * Math.PI
                        };
                    }
                }
            }
Ejemplo n.º 2
0
        public Transformation(LongLatBox longLatBox, Size imageSize)
        {
            // calculate projection origin
            ProjectionOrigin = new LongLat((longLatBox.East + longLatBox.West) / 2,
                                           (longLatBox.North + longLatBox.South) / 2);

            // get image corners from kml file
            var imageCornerLongLats = longLatBox.GetRotatedBoxCornerLongLats();

            // project them on flat surface
            var projectedImageCorners = new Dictionary <Corner, PointD>();

            projectedImageCorners[Corner.NorthWest] = imageCornerLongLats[Corner.NorthWest].Project(ProjectionOrigin);
            projectedImageCorners[Corner.SouthEast] = imageCornerLongLats[Corner.SouthEast].Project(ProjectionOrigin);

            // calculate transformation matrix
            TransformationMatrix = LinearAlgebraUtil.CalculateTransformationMatrix(
                projectedImageCorners[Corner.NorthWest], new PointD(0, 0),
                projectedImageCorners[Corner.SouthEast], new PointD(imageSize.Width - 1, imageSize.Height - 1), null, true);
        }