ESRI.ArcGIS.Client.Toolkit.DataSources.Kml.KmlToFeatureDefinition.ExtractPolygon C# (CSharp) Method

ExtractPolygon() private static method

Extracts a polygon from the input element and applies style information to the placemark descriptor.
private static ExtractPolygon ( KMLStyle kmlStyle, System.Xml.Linq.XElement geomElement ) : PlacemarkDescriptor
kmlStyle KMLStyle KML Style information.
geomElement System.Xml.Linq.XElement Polygon geometry information.
return PlacemarkDescriptor
        private static PlacemarkDescriptor ExtractPolygon(KMLStyle kmlStyle, XElement geomElement)
        {
            XNamespace kmlNS = geomElement.Name.Namespace;
            ESRI.ArcGIS.Client.Geometry.Polygon polygon = new Polygon();

            // Extract outer polygon boundary
            XElement boundary;
            boundary = geomElement.Element(kmlNS + "outerBoundaryIs");
            if (boundary != null)
            {
                ESRI.ArcGIS.Client.Geometry.PointCollection pts = ExtractRing(boundary);
                if (pts != null && pts.Count > 0)
                {
                    polygon.Rings.Add(pts);
                }
            }

            // Extract holes (if any)
            IEnumerable<XElement> holes =
                from e in geomElement.Descendants(kmlNS + "innerBoundaryIs")
                select e;
            foreach (XElement hole in holes)
            {
                ESRI.ArcGIS.Client.Geometry.PointCollection pts = ExtractRing(hole);
                if (pts != null && pts.Count > 0)
                {
                    polygon.Rings.Add(pts);
                }
            }

            // Create symbol and use style information
            PolygonSymbolDescriptor sym = new PolygonSymbolDescriptor();
            sym.style = kmlStyle;

            if (polygon.Rings.Count > 0)
            {
                // Create feature descriptor from geometry and other information
                return new PlacemarkDescriptor()
                {
                    Geometry = polygon,
                    Symbol = sym
                };
            }

            return null;
        }