Beispiel #1
0
        public void Parse( XDocument xDoc )
        {
            string xNs = "{" + xDoc.Root.Name.Namespace.ToString() + "}";

            // style parsing
            var styleList = from s in xDoc.Descendants(xNs + "Style")
                            select s;

            foreach (var i in styleList)//v
            {
                style newStyle = new style();
                newStyle.id = "#" + i.Attribute("id").Value;
                newStyle.label_color = i.Element(xNs + "LabelStyle").Element(xNs + "color").Value;
                newStyle.line_color = i.Element(xNs + "LineStyle").Element(xNs + "color").Value;
                newStyle.poly_color = i.Element(xNs + "PolyStyle").Element(xNs + "color").Value;

                Styles.Add(newStyle);
            }

            // site parsing
            var coordsStr = from f in xDoc.Descendants(xNs + "Placemark")
                                // where elementToFind.Contains(f.Parent.Element(xNs + "name").Value + f.Element(xNs + "name").Value)
                                //select f.Element(xNs + "LineString").Element(xNs + "coordinates");
                            select f;

            foreach (var i in coordsStr)
            {
                var y = i.Element(xNs + "MultiGeometry").Descendants(xNs + "Polygon").Descendants(xNs + "outerBoundaryIs").Descendants(xNs + "LinearRing").Descendants(xNs + "coordinates");
                char[] delemeters = { ',', ' ' };
                site newSite = new site();
                newSite.id = i.Attribute("id").Value;
                newSite.styleId = i.Element(xNs + "styleUrl").Value;
                newSite.name = i.Element(xNs + "name").Value;
                newSite.points = y.ElementAt(0).Value.ToString().TrimStart().Split(delemeters).ToList();
                while (newSite.points.Remove("0"))
                    ;

                newSite.styleRef = (from style in Styles
                                    where style.id == newSite.styleId
                                    select style).ElementAt(0);
                // assert even
                Debug.Assert((newSite.points.Count % 2) == 0);

                for (int j = 0; j < newSite.points.Count; j += 2)
                {
                    coord c = new coord();
                    c._x = double.Parse(newSite.points[j]);
                    c._y = double.Parse(newSite.points[j + 1]);
                    c.x = newSite.points[j];
                    c.y = newSite.points[j+1];
                    checkBoundary(c);
                    newSite.coords.Add(c);
                }

                Sites.Add(newSite);
            }
            Console.WriteLine(coordsStr.Count());

            Console.WriteLine("{0}:{1}", (_leftTop._y + _rightBottom._y) / 2, (_leftTop._x + _rightBottom._x) / 2);
        }
Beispiel #2
0
        public void Parse(XDocument xDoc)
        {
            string xNs = "{" + xDoc.Root.Name.Namespace.ToString() + "}";

            // style parsing
            var styleList = from s in xDoc.Descendants(xNs + "Style")
                            select s;

            foreach (var i in styleList)//v
            {
                style newStyle = new style();
                newStyle.id          = "#" + i.Attribute("id").Value;
                newStyle.label_color = i.Element(xNs + "LabelStyle").Element(xNs + "color").Value;
                newStyle.line_color  = i.Element(xNs + "LineStyle").Element(xNs + "color").Value;
                newStyle.poly_color  = i.Element(xNs + "PolyStyle").Element(xNs + "color").Value;

                Styles.Add(newStyle);
            }

            // site parsing
            var coordsStr = from f in xDoc.Descendants(xNs + "Placemark")
                            // where elementToFind.Contains(f.Parent.Element(xNs + "name").Value + f.Element(xNs + "name").Value)
                            //select f.Element(xNs + "LineString").Element(xNs + "coordinates");
                            select f;

            foreach (var i in coordsStr)
            {
                var    y          = i.Element(xNs + "MultiGeometry").Descendants(xNs + "Polygon").Descendants(xNs + "outerBoundaryIs").Descendants(xNs + "LinearRing").Descendants(xNs + "coordinates");
                char[] delemeters = { ',', ' ' };
                site   newSite    = new site();
                newSite.id      = i.Attribute("id").Value;
                newSite.styleId = i.Element(xNs + "styleUrl").Value;
                newSite.name    = i.Element(xNs + "name").Value;
                newSite.points  = y.ElementAt(0).Value.ToString().TrimStart().Split(delemeters).ToList();
                while (newSite.points.Remove("0"))
                {
                    ;
                }

                newSite.styleRef = (from style in Styles
                                    where style.id == newSite.styleId
                                    select style).ElementAt(0);
                // assert even
                Debug.Assert((newSite.points.Count % 2) == 0);

                for (int j = 0; j < newSite.points.Count; j += 2)
                {
                    coord c = new coord();
                    c._x = double.Parse(newSite.points[j]);
                    c._y = double.Parse(newSite.points[j + 1]);
                    c.x  = newSite.points[j];
                    c.y  = newSite.points[j + 1];
                    checkBoundary(c);
                    newSite.coords.Add(c);
                }

                Sites.Add(newSite);
            }
            Console.WriteLine(coordsStr.Count());

            Console.WriteLine("{0}:{1}", (_leftTop._y + _rightBottom._y) / 2, (_leftTop._x + _rightBottom._x) / 2);
        }