Example #1
0
        public Request(XElement node, string @namespace)
        {
            foreach (var element in node.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "GetCapabilities":
                    GetCapabilities = new OperationType(element, @namespace);
                    break;

                case "GetMap":
                    GetMap = new OperationType(element, @namespace);
                    break;

                case "GetFeatureInfo":
                    GetFeatureInfo = new OperationType(element, @namespace);
                    break;

                default:
                    ExtendedOperation.Add(element.Name.LocalName, new OperationType(element, @namespace));
                    break;
                }
            }

            if (GetCapabilities == null)
            {
                throw WmsParsingException.ElementNotFound("GetCapabilities");
            }

            if (GetMap == null)
            {
                throw WmsParsingException.ElementNotFound("GetMap");
            }
        }
        public ExGeographicBoundingBox(XElement node, string @namespace)
        {
            var element = node.Element(XName.Get("westBoundLongitude", @namespace));

            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("westBoundLongitude");
            }
            WestBoundLongitude = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);

            element = node.Element(XName.Get("eastBoundLongitude", @namespace));
            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("eastBoundLongitude");
            }
            EastBoundLongitude = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);

            element = node.Element(XName.Get("northBoundLatitude", @namespace));
            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("northBoundLatitude");
            }
            NorthBoundLatitude = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);

            element = node.Element(XName.Get("southBoundLatitude", @namespace));
            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("southBoundLatitude");
            }
            SouthBoundLatitude = double.Parse(element.Value, NumberFormatInfo.InvariantInfo);
        }
Example #3
0
        public Capability(XElement node, string @namespace)
        {
            var element = node.Element(XName.Get("Request", @namespace));

            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("Request");
            }
            Request = new Request(element, @namespace);

            foreach (var el in node.Elements())
            {
                if (el.Name.LocalName == "Request" || el.Name.LocalName == "Layer")
                {
                    continue;
                }

                if (el.Name.LocalName == "Exception")
                {
                    Exception.Add(el.Value);
                    continue;
                }

                ExtendedCapabilities.Add(el.Name, el);
            }

            if (Exception.Count == 0)
            {
                throw WmsParsingException.ElementNotFound("Exception");
            }

            bool baseNodeCreated = false;

            foreach (var layerNode in node.Elements(XName.Get("Layer", @namespace)))
            {
                var layer = new Layer(layerNode, @namespace);
                if (_layerField == null)
                {
                    _layerField = layer;
                }

                else if (_layerField != null && !baseNodeCreated)
                {
                    var tmpLayer = new Layer {
                        Title = "Root Layer"
                    };
                    tmpLayer.ChildLayers.Add(Layer);
                    tmpLayer.ChildLayers.Add(layer);
                    Layer           = tmpLayer;
                    baseNodeCreated = true;
                }
                else
                {
                    _layerField.ChildLayers.Add(layer);
                }
            }
        }
Example #4
0
        public WmsCapabilities(XDocument doc)
            : this()
        {
            if (doc.Root != null && doc.Root.Name == "ServiceExceptionReport")
            {
                ServiceExceptionReport = new ServiceExceptionReport(doc.Root, "");
                return;
            }

            var node = doc.Element(XName.Get("WMT_MS_Capabilities"));
            if (node == null) node = doc.Element(XName.Get("WMS_Capabilities"));
            if (node == null)
            {
                // try load root node with xmlns="http://www.opengis.net/wms"
                node = doc.Element(XName.Get("WMS_Capabilities", "http://www.opengis.net/wms"));
                if (node == null)
                {
                    throw WmsParsingException.ElementNotFound("WMS_Capabilities or WMT_MS_Capabilities");
                }
            }

            var att = node.Attribute(XName.Get("version"));
            if (att == null)
                throw WmsParsingException.AttributeNotFound("version");
            Version = new WmsVersion(att.Value);

            var @namespace = Version.Version == WmsVersionEnum.Version_1_3_0
                          ? "http://www.opengis.net/wms"
                          : string.Empty;
            XmlObject.Namespace = @namespace;

            att = node.Attribute("updateSequence");
            if (att != null)
                UpdateSequence = int.Parse(att.Value, NumberFormatInfo.InvariantInfo);

            var element = node.Element(XName.Get("Service", @namespace));
            if (element == null)
            {
                XmlObject.Namespace = @namespace = string.Empty;
                element = node.Element(XName.Get("Service", @namespace));
            }
            if (element == null)
                throw WmsParsingException.ElementNotFound("Service");

            Service = new Service(element, @namespace);

            element = node.Element(XName.Get("Capability", @namespace));

            if (element == null)
                throw WmsParsingException.ElementNotFound("Capability");

            Capability = new Capability(element, @namespace);
        }
        public FeatureListURL(XElement node, string ns)
        {
            var element = node.Element(XName.Get("Format", ns));

            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("Format");
            }
            Format = element.Value;

            element = node.Element(XName.Get("OnlineResource", ns));
            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("OnlineResource");
            }
            OnlineResource = new OnlineResource(element, ns);
        }
Example #6
0
        public OperationType(XElement node, string @namespace)
        {
            foreach (var formatNode in node.Elements(XName.Get("Format", @namespace)))
            {
                Format.Add(formatNode.Value);
            }

            foreach (var dcptype in node.Elements(XName.Get("DCPType", @namespace)))
            {
                DCPType.Add(new DCPType(dcptype, @namespace));
            }

            if (Format.Count < 1)
            {
                throw WmsParsingException.ElementNotFound("Format");
            }
            if (DCPType.Count < 1)
            {
                throw WmsParsingException.ElementNotFound("DCPType");
            }
        }
Example #7
0
        public Style(XElement node, string @namespace)
        {
            var element = node.Element(XName.Get("Name", @namespace));

            if (element == null)
            {
                throw WmsParsingException.ElementNotFound("Name");
            }
            Name = element.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));
            if (element != null)
            {
                Abstract = element.Value;
            }

            foreach (var el in node.Elements(XName.Get("LegendURL", @namespace)))
            {
                LegendURL.Add(new LegendURL(el, @namespace));
            }

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

            element = node.Element(XName.Get("StyleURL", @namespace));
            if (element != null)
            {
                StyleURL = new StyleURL(element, @namespace);
            }
        }
Example #8
0
        public override void ReadXml(XmlReader reader)
        {
            if (CheckEmptyNode(reader, "Capability", string.Empty, true))
            {
                throw WmsParsingException.ElementNotFound("Capability");
            }

            bool baseLayerCreated = false;

            while (!reader.EOF)
            {
                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case "Request":
                        _requestField = new Request();
                        _requestField.ReadXml(reader.ReadSubtree());
                        break;

                    case "Exception":
                        if (_exceptionField == null)
                        {
                            _exceptionField = new List <string>();
                        }
                        var subReader = reader.ReadSubtree();
                        while (!subReader.EOF)
                        {
                            reader.ReadStartElement("Format");
                            var format = reader.ReadContentAsString();
                            reader.ReadEndElement();
                            _exceptionField.Add(format);
                        }
                        break;

                    case "Layer":
                        if (_layerField == null)
                        {
                            _layerField = new Layer();
                            _layerField.ReadXml(reader);
                        }
                        else
                        {
                            if (!baseLayerCreated)
                            {
                                var tmp = _layerField;
                                _layerField      = new Layer();
                                _layerField.Name = _layerField.Title = "Created base layer";
                                _layerField.ChildLayers.Add(tmp);
                                baseLayerCreated = true;
                            }
                            var layer = new Layer();
                            layer.ReadXml(reader);
                            _layerField.ChildLayers.Add(layer);
                        }
                        break;

                    default:
                        ExtendedCapabilities.Add(XName.Get(reader.LocalName, reader.NamespaceURI), XNode.ReadFrom(reader));
                        break;
                    }
                }
                else
                {
                    reader.Read();
                }
            }
        }
Example #9
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.ToLower().StartsWith("ogc:wms"))
                {
                    Debug.WriteLine("Warning: Invalid service name: '{0}'. Must be 'OGC:WMS'", value);
                }
                Name = ServiceName.WMS;
            }

            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);
            }
        }
Example #10
0
        public override void ReadXml(XmlReader reader)
        {
            if (CheckEmptyNode(reader, "Service", string.Empty))
            {
                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();
                }
            }
        }