Exemple #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);
        }
Exemple #3
0
        public WmsCapabilities(XDocument doc)
            : this()
        {
            if (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"));
            }

            var att = node.Attribute(XName.Get("version"));

            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("version");
            }
            Version = new WmsVersion(att.Value);

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

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

            XmlObject.Namespace = @namespace;

            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);
        }
Exemple #4
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();
                    tmpLayer.Title = "Root Layer";
                    tmpLayer.ChildLayers.Add(Layer);
                    tmpLayer.ChildLayers.Add(layer);
                    Layer           = tmpLayer;
                    baseNodeCreated = true;
                }
                else
                {
                    _layerField.ChildLayers.Add(layer);
                }
            }
        }
Exemple #5
0
        public Dimension(XElement el, string ns)
        {
            var att = el.Attribute("name");

            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("name");
            }
            Name = att.Value;

            att = el.Attribute("units");
            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("units");
            }
            Units = att.Value;

            att        = el.Attribute("unitSymbol");
            UnitSymbol = att != null ? att.Value : string.Empty;

            att     = el.Attribute("default");
            Default = att != null ? att.Value : string.Empty;

            att = el.Attribute("multipleValues");
            if (att == null)
            {
                MultipleValues = null;
            }
            else
            {
                MultipleValues = att.Value == "1";
            }

            att = el.Attribute("nearestValue");
            if (att == null)
            {
                NearestValue = null;
            }
            else
            {
                NearestValue = att.Value == "1";
            }

            att = el.Attribute("current");
            if (att == null)
            {
                Current = null;
            }
            else
            {
                Current = att.Value == "1";
            }

            Value = el.Value;
        }
Exemple #6
0
        public DataURL(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);
        }
Exemple #7
0
        public AuthorityURL(XElement node, string @namespace)
        {
            var att = node.Attribute("name");

            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("name");
            }

            Name = att.Value;

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

            if (element != null)
            {
                OnlineResource = new OnlineResource(element, @namespace);
            }
        }
Exemple #8
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");
            }
        }
Exemple #9
0
        public MetadataURL(XElement node, string @namespace)
        {
            var att = node.Attribute("type");

            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("type");
            }

            Type = att.Value;

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

            Format = element == null ? "png" : element.Value;

            element = node.Element(XName.Get("OnlineResource", @namespace));
            if (element != null)
            {
                OnlineResource = new OnlineResource(element, @namespace);
            }
        }
Exemple #10
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);
            }
        }
Exemple #11
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();
                }
            }
        }
Exemple #12
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);
            }
        }
Exemple #13
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();
                }
            }
        }
Exemple #14
0
        public BoundingBox(XElement node, string nameSpace)
        {
            var att = node.Attribute(XName.Get("CRS"));

            if (att == null)
            {
                att = node.Attribute(XName.Get("crs"));
            }
            if (att == null)
            {
                att = node.Attribute(XName.Get("SRS"));
            }
            if (att == null)
            {
                att = node.Attribute(XName.Get("srs"));
            }
            if (att != null)
            {
                CRS = att.Value;
            }
            else
            {
                throw WmsParsingException.AttributeNotFound("CRS/SRS");
            }

            att = node.Attribute(XName.Get("minx"));
            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("minx");
            }
            MinX = double.Parse(att.Value, NumberFormatInfo.InvariantInfo);
            att  = node.Attribute(XName.Get("maxx"));
            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("maxx");
            }
            MaxX = double.Parse(att.Value, NumberFormatInfo.InvariantInfo);
            att  = node.Attribute(XName.Get("miny"));
            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("miny");
            }
            MinY = double.Parse(att.Value, NumberFormatInfo.InvariantInfo);
            att  = node.Attribute(XName.Get("maxy"));
            if (att == null)
            {
                throw WmsParsingException.AttributeNotFound("maxy");
            }
            MaxY = double.Parse(att.Value, NumberFormatInfo.InvariantInfo);

            att = node.Attribute(XName.Get("resx"));
            if (att != null)
            {
                ResX = double.Parse(att.Value, NumberFormatInfo.InvariantInfo);
            }
            att = node.Attribute(XName.Get("resy"));
            if (att != null)
            {
                ResY = double.Parse(att.Value, NumberFormatInfo.InvariantInfo);
            }
        }