Exemplo n.º 1
0
        public override void WriteXml(XmlWriter writer)
        {
            writer.WriteElementString("Name", Namespace, Name.ToString());
            writer.WriteElementString("Title", Namespace, Title);
            if (!string.IsNullOrEmpty(Abstract))
            {
                writer.WriteElementString("Abstract", Namespace, Abstract);
            }
            if (_keywordListField != null && _keywordListField.Keyword.Count > 0)
            {
                writer.WriteStartElement("KeywordList", Namespace);
                KeywordList.WriteXml(writer);
                writer.WriteEndElement();
            }

            writer.WriteStartElement("OnlineResource", Namespace);
            OnlineResource.WriteXml(writer);
            writer.WriteEndElement();

            if (_contactInformationField != null)
            {
                writer.WriteStartElement("ContactInformation", Namespace);
                _contactInformationField.WriteXml(writer);
                writer.WriteEndElement();
            }

            if (!string.IsNullOrEmpty(Fees))
            {
                writer.WriteElementString("Fees", Namespace, Fees);
            }

            if (!string.IsNullOrEmpty(AccessConstraints))
            {
                writer.WriteElementString("AccessConstraints", Namespace, AccessConstraints);
            }

            if (LayerLimit.HasValue)
            {
                writer.WriteElementString("LayerLimit", Namespace, LayerLimit.Value.ToString());
            }
            if (MaxWidth.HasValue)
            {
                writer.WriteElementString("MaxWidth", Namespace, MaxWidth.Value.ToString());
            }
            if (MaxHeight.HasValue)
            {
                writer.WriteElementString("MaxHeight", Namespace, MaxHeight.Value.ToString());
            }
        }
Exemplo n.º 2
0
        public Layer(XElement node, string ns)
        {
            var att = node.Attribute(XName.Get("queryable"));

            Queryable = att != null && att.Value == "1";

            att      = node.Attribute(XName.Get("cascaded"));
            Cascaded = att != null?int.Parse(att.Value, NumberFormatInfo.InvariantInfo) : 0;

            att    = node.Attribute(XName.Get("opaque"));
            Opaque = att != null && att.Value == "1";

            att       = node.Attribute(XName.Get("noSubsets"));
            NoSubsets = att != null && att.Value == "1";

            att        = node.Attribute(XName.Get("fixedWidth"));
            FixedWidth = att != null?int.Parse(att.Value, NumberFormatInfo.InvariantInfo) : 0;

            att         = node.Attribute(XName.Get("fixedHeight"));
            FixedHeight = att != null?int.Parse(att.Value, NumberFormatInfo.InvariantInfo) : 0;

            var element = node.Element(XName.Get("Name", ns));

            Name = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("Title", ns));
            Title   = element != null ? element.Value : string.Empty;

            element  = node.Element(XName.Get("Abstract", ns));
            Abstract = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("KeywordList", ns));
            if (element != null)
            {
                _keywordListField = new KeywordList(element, ns);
            }

            foreach (var el in node.Elements(XName.Get("CRS", ns)))
            {
                _crsField.Add(el.Value);
            }

            foreach (var el in node.Elements(XName.Get("SRS", ns)))
            {
                _srsField.Add(el.Value);
            }

            element = node.Element(XName.Get("EX_GeographicBoundingBox", ns));
            if (element != null)
            {
                ExGeographicBoundingBox = new ExGeographicBoundingBox(element, ns);
            }

            BoundingBox = new List <BoundingBox>();
            foreach (var el in node.Elements(XName.Get("BoundingBox", ns)))
            {
                BoundingBox.Add(new BoundingBox(el, ns));
            }

            Dimension = new List <Dimension>();
            foreach (var el in node.Elements(XName.Get("Dimension", ns)))
            {
                Dimension.Add(new Dimension(el, ns));
            }

            element = node.Element(XName.Get("Attribution", ns));
            if (element != null)
            {
                Attribution = new Attribution(element, ns);
            }

            AuthorityURL = new List <AuthorityURL>();
            foreach (var el in node.Elements(XName.Get("AuthorityURL", ns)))
            {
                AuthorityURL.Add(new AuthorityURL(el, ns));
            }

            Identifier = new List <Identifier>();
            foreach (var el in node.Elements(XName.Get("Identifier", ns)))
            {
                Identifier.Add(new Identifier(el, ns));
            }

            MetadataURL = new List <MetadataURL>();
            foreach (var el in node.Elements(XName.Get("MetadataURL", ns)))
            {
                MetadataURL.Add(new MetadataURL(el, ns));
            }

            DataURL = new List <DataURL>();
            foreach (var el in node.Elements(XName.Get("DataURL", ns)))
            {
                DataURL.Add(new DataURL(el, ns));
            }

            FeatureListURL = new List <FeatureListURL>();
            foreach (var el in node.Elements(XName.Get("FeatureListURL", ns)))
            {
                FeatureListURL.Add(new FeatureListURL(el, ns));
            }

            Style = new List <Style>();
            foreach (var el in node.Elements(XName.Get("Style", ns)))
            {
                Style.Add(new Style(el, ns));
            }

            element = node.Element(XName.Get("MinScaleDenominator", ns));
            if (element != null)
            {
                MinScaleDenominator = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);
            }

            element = node.Element(XName.Get("MaxScaleDenominator", ns));
            if (element != null)
            {
                MaxScaleDenominator = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);
            }

            foreach (var layerNode in node.Elements(XName.Get("Layer", ns)))
            {
                ChildLayers.Add(new Layer(layerNode, ns));
            }
        }
Exemplo n.º 3
0
        public Service(XElement node, string @namespace)
        {
            XElement element;

            if (ParseName)
            {
                element = node.Element(XName.Get("Name", @namespace));
                if (element == null)
                {
                    throw WmsParsingException.ElementNotFound("Name");
                }
                var value = element.Value;
                if (value.StartsWith("OGC:"))
                {
                    value = value.Substring(4);
                }
                try
                {
                    Name = (ServiceName)Enum.Parse(typeof(ServiceName), value, true);
                }
                catch (System.Exception exception)
                {
                    throw new WmsParsingException(String.Format("Invalid service name: {0}. Must be WMS", value),
                                                  exception);
                }

                if (Name != ServiceName.WMS)
                {
                    throw new WmsParsingException(String.Format("Invalid service name: {0}. Must be WMS", value));
                }
            }

            element = node.Element(XName.Get("Title", @namespace));
            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("Title");
            }
            Title = element.Value;

            element  = node.Element(XName.Get("Abstract", @namespace));
            Abstract = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("KeywordList", @namespace));
            if (element != null)
            {
                KeywordList = new KeywordList(element, @namespace);
            }

            element = node.Element(XName.Get("OnlineResource", @namespace));
            if (element != null)
            {
                OnlineResource = new OnlineResource(element, @namespace);
            }

            element = node.Element(XName.Get("ContactInformation", @namespace));
            if (element != null)
            {
                ContactInformation = new ContactInformation(element, @namespace);
            }

            element = node.Element(XName.Get("Fees", @namespace));
            Fees    = element != null ? element.Value : string.Empty;

            element           = node.Element(XName.Get("AccessConstraints", @namespace));
            AccessConstraints = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("LayerLimit", @namespace));
            if (element == null)
            {
                LayerLimit = null;
            }
            else
            {
                LayerLimit = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
            }

            element = node.Element(XName.Get("MaxWidth", @namespace));
            if (element == null)
            {
                MaxWidth = null;
            }
            else
            {
                MaxWidth = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
            }

            element = node.Element(XName.Get("MaxHeight", @namespace));
            if (element == null)
            {
                MaxHeight = null;
            }
            else
            {
                MaxHeight = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
            }
        }
Exemplo n.º 4
0
        public override void ReadXml(XmlReader reader)
        {
            if (CheckEmptyNode(reader, "Service", string.Empty, true))
            {
                throw WmsParsingException.ElementNotFound("Service");
            }

            while (!reader.EOF)
            {
                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case "Name":
                        string       name   = reader.ReadElementContentAsString();
                        const string prefix = "ogc:";
                        if (name.ToLower().StartsWith(prefix))
                        {
                            name = name.Substring(prefix.Length);
                        }
                        Name = (ServiceName)Enum.Parse(typeof(ServiceName), name, true);
                        break;

                    case "Title":
                        Title = reader.ReadElementContentAsString();
                        break;

                    case "Abstact":
                        Abstract = reader.ReadElementContentAsString();
                        break;

                    case "KeywordList":
                        KeywordList = new KeywordList();
                        KeywordList.ReadXml(reader);
                        break;

                    case "OnlineResource":
                        OnlineResource = new OnlineResource();
                        OnlineResource.ReadXml(reader);
                        break;

                    case "ContactInformation":
                        ContactInformation = new ContactInformation();
                        ContactInformation.ReadXml(reader);
                        break;

                    case "Fees":
                        Fees = reader.ReadElementContentAsString();
                        break;

                    case "AccessConstraints":
                        AccessConstraints = reader.ReadElementContentAsString();
                        break;

                    case "LayerLimit":
                        LayerLimit = reader.ReadElementContentAsInt();
                        break;

                    case "MaxWidth":
                        MaxWidth = reader.ReadElementContentAsInt();
                        break;

                    case "MaxHeight":
                        MaxHeight = reader.ReadElementContentAsInt();
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }
                else
                {
                    reader.Read();
                }
            }
        }
Exemplo n.º 5
0
        public Service(XElement node, string @namespace)
        {
            XElement element;
            if (ParseName)
            {
                element = node.Element(XName.Get("Name", @namespace));
                if (element == null)
                    throw WmsParsingException.ElementNotFound("Name");
                var value = element.Value;
                if (value.StartsWith("OGC:")) value = value.Substring(4);
                try
                {
                    Name = (ServiceName) Enum.Parse(typeof (ServiceName), value, true);
                }
                catch (System.Exception exception)
                {
                    throw new WmsParsingException(String.Format("Invalid service name: {0}. Must be WMS", value),
                                                  exception);
                }

                if (Name != ServiceName.WMS)
                    throw new WmsParsingException(String.Format("Invalid service name: {0}. Must be WMS", value));
            }

            element = node.Element(XName.Get("Title", @namespace));
            if (element == null)
                throw WmsParsingException.ElementNotFound("Title");
            Title = element.Value;

            element = node.Element(XName.Get("Abstract", @namespace));
            Abstract = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("KeywordList", @namespace));
            if (element != null)
                KeywordList = new KeywordList(element, @namespace);

            element = node.Element(XName.Get("OnlineResource", @namespace));
            if (element != null)
                OnlineResource = new OnlineResource(element, @namespace);

            element = node.Element(XName.Get("ContactInformation", @namespace));
            if (element != null)
                ContactInformation = new ContactInformation(element, @namespace);

            element = node.Element(XName.Get("Fees", @namespace));
            Fees = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("AccessConstraints", @namespace));
            AccessConstraints = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("LayerLimit", @namespace));
            if (element == null)
                LayerLimit = null;
            else
                LayerLimit = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);

            element = node.Element(XName.Get("MaxWidth", @namespace));
            if (element == null)
                MaxWidth = null;
            else
                MaxWidth = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);

            element = node.Element(XName.Get("MaxHeight", @namespace));
            if (element == null)
                MaxHeight = null;
            else
                MaxHeight = int.Parse(element.Value, NumberFormatInfo.InvariantInfo);
        }
Exemplo n.º 6
0
 public override void ReadXml(XmlReader reader)
 {
     if (CheckEmptyNode(reader, "Service", string.Empty, true))
         throw WmsParsingException.ElementNotFound("Service");
    
     while (!reader.EOF)
     {
         if (reader.IsStartElement())
         {
             switch (reader.LocalName)
             {
                 case "Name":
                     string name = reader.ReadElementContentAsString();
                     const string prefix = "ogc:";
                     if (name.ToLower().StartsWith(prefix)) name = name.Substring(prefix.Length);
                     Name = (ServiceName)Enum.Parse(typeof(ServiceName), name , true);
                     break;
                 case "Title":
                     Title = reader.ReadElementContentAsString();
                     break;
                 case "Abstact":
                     Abstract = reader.ReadElementContentAsString();
                     break;
                 case "KeywordList":
                     KeywordList = new KeywordList();
                     KeywordList.ReadXml(reader);
                     break;
                 case "OnlineResource":
                     OnlineResource = new OnlineResource();
                     OnlineResource.ReadXml(reader);
                     break;
                 case "ContactInformation":
                     ContactInformation = new ContactInformation();
                     ContactInformation.ReadXml(reader);
                     break;
                 case "Fees":
                     Fees = reader.ReadElementContentAsString();
                     break;
                 case "AccessConstraints":
                     AccessConstraints = reader.ReadElementContentAsString();
                     break;
                 case "LayerLimit":
                     LayerLimit = reader.ReadElementContentAsInt();
                     break;
                 case "MaxWidth":
                     MaxWidth = reader.ReadElementContentAsInt();
                     break;
                 case "MaxHeight":
                     MaxHeight = reader.ReadElementContentAsInt();
                     break;
                 default:
                     reader.Skip();
                     break;
             }
         }
         else
         {
             reader.Read();
         }
     }
 }
Exemplo n.º 7
0
        public Layer(XElement node, string ns)
        {
            var att = node.Attribute(XName.Get("queryable"));
            Queryable = att != null && att.Value == "1";

            att = node.Attribute(XName.Get("cascaded"));
            Cascaded = att != null ? int.Parse(att.Value, NumberFormatInfo.InvariantInfo) : 0;

            att = node.Attribute(XName.Get("opaque"));
            Opaque = att != null && att.Value == "1";

            att = node.Attribute(XName.Get("noSubsets"));
            NoSubsets = att != null && att.Value == "1";

            att = node.Attribute(XName.Get("fixedWidth"));
            FixedWidth = att != null ? int.Parse(att.Value, NumberFormatInfo.InvariantInfo) : 0;

            att = node.Attribute(XName.Get("fixedHeight"));
            FixedHeight = att != null ? int.Parse(att.Value, NumberFormatInfo.InvariantInfo) : 0;

            var element = node.Element(XName.Get("Name", ns));
            Name = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("Title", ns));
            Title = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("Abstract", ns));
            Abstract = element != null ? element.Value : string.Empty;

            element = node.Element(XName.Get("KeywordList", ns));
            if (element != null) _keywordListField = new KeywordList(element, ns);

            foreach (var el in node.Elements(XName.Get("CRS", ns)))
                _crsField.Add(el.Value);

            if (_crsField.Count == 0)
            { }

            element = node.Element(XName.Get("EX_GeographicBoundingBox", ns));
            if (element != null) ExGeographicBoundingBox = new ExGeographicBoundingBox(element, ns);

            BoundingBox = new List<BoundingBox>();
            foreach (var el in node.Elements(XName.Get("BoundingBox", ns)))
                BoundingBox.Add(new BoundingBox(el, ns));

            Dimension = new List<Dimension>();
            foreach (var el in node.Elements(XName.Get("Dimension", ns)))
                Dimension.Add(new Dimension(el, ns));

            element = node.Element(XName.Get("Attribution", ns));
            if (element != null) Attribution = new Attribution(element, ns);

            AuthorityURL = new List<AuthorityURL>();
            foreach (var el in node.Elements(XName.Get("AuthorityURL", ns)))
                AuthorityURL.Add(new AuthorityURL(el, ns));

            Identifier = new List<Identifier>();
            foreach (var el in node.Elements(XName.Get("Identifier", ns)))
                Identifier.Add(new Identifier(el, ns));

            MetadataURL = new List<MetadataURL>();
            foreach (var el in node.Elements(XName.Get("MetadataURL", ns)))
                MetadataURL.Add(new MetadataURL(el, ns));

            DataURL = new List<DataURL>();
            foreach (var el in node.Elements(XName.Get("DataURL", ns)))
                DataURL.Add(new DataURL(el, ns));

            FeatureListURL = new List<FeatureListURL>();
            foreach (var el in node.Elements(XName.Get("FeatureListURL", ns)))
                FeatureListURL.Add(new FeatureListURL(el, ns));

            Style = new List<Style>();
            foreach (var el in node.Elements(XName.Get("Style", ns)))
                Style.Add(new Style(el, ns));

            element = node.Element(XName.Get("MinScaleDenominator", ns));
            if (element != null)
                MinScaleDenominator = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);

            element = node.Element(XName.Get("MaxScaleDenominator", ns));
            if (element != null)
                MaxScaleDenominator = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);

            foreach (var layerNode in node.Elements(XName.Get("Layer", ns)))
                ChildLayers.Add(new Layer(layerNode, ns));
        }