public static CountryGeography Create(XmlElement element)
        {
            CountryGeography country = new CountryGeography
            {
                Name        = element.SelectSingleNode("name")?.InnerText,
                Description = element.SelectSingleNode("description")?.InnerText
            };

            XmlNode lookatNode = element.SelectSingleNode("LookAt");

            if (lookatNode != null)
            {
                string latText = lookatNode.SelectSingleNode("latitude")?.InnerText;
                if (latText != null)
                {
                    country.CentralLatitude = double.Parse(latText);
                }

                string longText = lookatNode.SelectSingleNode("longitude")?.InnerText;
                if (longText != null)
                {
                    country.CentralLongitude = double.Parse(longText);
                }
            }

            XmlNodeList boundaryRingCoordinates =
                element.SelectNodes("MultiGeometry/Polygon/outerBoundaryIs/LinearRing");

            if (boundaryRingCoordinates != null)
            {
                foreach (object boundary in boundaryRingCoordinates)
                {
                    XmlElement boundaryElement = boundary as XmlElement;
                    if (boundaryElement != null)
                    {
                        string          coordinateText = boundaryElement.SelectSingleNode("coordinates")?.InnerText;
                        PolygonBoundary landBlock      = new PolygonBoundary(coordinateText);
                        country.LandBlocks.Add(landBlock);
                    }
                }
            }

            country.UpdateLatLongs();

            country.XmlElement = element;

            return(country);
        }
示例#2
0
        private void ParseCountries(XmlDocument doc)
        {
            doc.SelectNodes("//Document/Placemark/name");

            XmlNodeList placemarkNodes = doc.SelectNodes("//Document/Placemark");

            if (placemarkNodes == null)
            {
                return;
            }

            foreach (object node in placemarkNodes)
            {
                XmlElement       element = (XmlElement)node;
                CountryGeography country = CountryGeography.Create(element);
                _countries.Add(country.Name, country);
            }
        }