Наследование: IClient
 public void Test130()
 {
     Client c = new Client("http://wms.iter.dk/example_capabilities_1_3_0.xml");
     Assert.AreEqual(3, c.ServiceDescription.Keywords.Length);
     Assert.AreEqual("1.3.0", c.Version);
     Assert.AreEqual("http://hostname/path?", c.GetMapRequests[0].OnlineResource);
     Assert.AreEqual("image/gif", c.GetMapOutputFormats[0]);
     Assert.AreEqual(4, c.Layer.ChildLayers.Length);
 }
 public void TestDemisv111()
 {
     Client c = new Client("http://www2.demis.nl/worldmap/wms.asp");
     Assert.AreEqual("World Map", c.ServiceDescription.Title);
     Assert.AreEqual("1.1.1", c.Version);
     Assert.AreEqual("http://www2.demis.nl/WMS/wms.ashx?wms=WorldMap&", c.GetMapRequests[0].OnlineResource);
     Assert.AreEqual("image/png", c.GetMapOutputFormats[0]);
     Assert.AreEqual(20, c.Layer.ChildLayers.Length);
 }
Пример #3
0
        private Client CreateClientFromXmlResult(string xmlFilename)
        {
            var resourceName = typeof (WmsLayerTest).Namespace + "." + xmlFilename;
            var resourceStream = typeof(WmsLayerTest).Assembly.GetManifestResourceStream(resourceName);
            Assert.That(resourceStream, Is.Not.Null, "Wrong test: Invalid resource name");

            var buffer = new byte[resourceStream.Length];
            resourceStream.Read(buffer, 0, Convert.ToInt32(resourceStream.Length));

            var client = new Client(buffer);
            return client;
        }
Пример #4
0
 /// <summary>
 /// Initializes a new layer, and downloads and parses the service description
 /// </summary>
 /// <param name="layername">Layername</param>
 /// <param name="url">Url of WMS server</param>
 /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param>
 /// <param name="proxy">Proxy</param>
 public WmsLayer(string layername, string url, TimeSpan cachetime, System.Net.WebProxy proxy)
 {
     _Proxy           = proxy;
     _TimeOut         = 10000;
     this.LayerName   = layername;
     _ContinueOnError = true;
     if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null)
     {
         wmsClient = (SharpMap.Web.Wms.Client)System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url];
     }
     else
     {
         wmsClient = new SharpMap.Web.Wms.Client(url, _Proxy);
         if (System.Web.HttpContext.Current != null)
         {
             System.Web.HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, wmsClient, null,
                                                         System.Web.Caching.Cache.NoAbsoluteExpiration, cachetime);
         }
     }
     //Set default mimetype - We prefer compressed formats
     if (OutputFormats.Contains("image/jpeg"))
     {
         _MimeType = "image/jpeg";
     }
     else if (OutputFormats.Contains("image/png"))
     {
         _MimeType = "image/png";
     }
     else if (OutputFormats.Contains("image/gif"))
     {
         _MimeType = "image/gif";
     }
     else //None of the default formats supported - Look for the first supported output format
     {
         bool formatSupported = false;
         foreach (System.Drawing.Imaging.ImageCodecInfo encoder in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders())
         {
             if (OutputFormats.Contains(encoder.MimeType.ToLower()))
             {
                 formatSupported = true;
                 _MimeType       = encoder.MimeType;
                 break;
             }
         }
         if (!formatSupported)
         {
             throw new ArgumentException("GDI+ doesn't not support any of the mimetypes supported by this WMS service");
         }
     }
     _LayerList  = new Collection <string>();
     _StylesList = new Collection <string>();
 }
Пример #5
0
        /// <summary>
        /// Initializes a new layer, and downloads and parses the service description
        /// </summary>
        /// <param name="layername">Layername</param>
        /// <param name="url">Url of WMS server's Capabilties</param>
        /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param>
        /// <param name="proxy">Proxy</param>
        public TiledWmsLayer(string layername, string url, TimeSpan cachetime, System.Net.WebProxy proxy)
        {
            _Proxy           = proxy;
            _TimeOut         = 10000;
            this.LayerName   = layername;
            _ContinueOnError = true;

            if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null)
            {
                _WmsClient = (Client)System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url];
            }
            else
            {
                _WmsClient = new Client(url, _Proxy);
                if (System.Web.HttpContext.Current != null)
                {
                    System.Web.HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, _WmsClient, null,
                                                                System.Web.Caching.Cache.NoAbsoluteExpiration, cachetime);
                }
            }
            _TileSets = TileSet.ParseVendorSpecificCapabilitiesNode(_WmsClient.VendorSpecificCapabilities);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new layer, and downloads and parses the service description
        /// </summary>
        /// <param name="layername">Layername</param>
        /// <param name="url">Url of WMS server's Capabilties</param>
        /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param>
        /// <param name="proxy">Proxy</param>
        public TiledWmsLayer(string layername, string url, TimeSpan cachetime, WebProxy proxy)
        {
            _Proxy = proxy;
            _TimeOut = 10000;
            LayerName = layername;
            _ContinueOnError = true;

            if (HttpContext.Current != null && HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null)
            {
                _WmsClient = (Client) HttpContext.Current.Cache["SharpMap_WmsClient_" + url];
            }
            else
            {
                _WmsClient = new Client(url, _Proxy);
                if (HttpContext.Current != null)
                    HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, _WmsClient, null,
                                                     Cache.NoAbsoluteExpiration, cachetime);
            }
            _TileSets = TileSet.ParseVendorSpecificCapabilitiesNode(_WmsClient.VendorSpecificCapabilities);
        }
Пример #7
0
        /// <summary>
        /// Recursive method for adding all WMS layers to layer list
        /// Skips "top level" layer if addFirstLayer is false
        /// </summary>
        /// <param name="wmsServerLayer"></param>
        /// <param name="addFirstLayer"></param>
        /// <returns></returns>
        public void AddChildLayers(Client.WmsServerLayer wmsServerLayer, bool addFirstLayer)
        {
            if (addFirstLayer)
            {
                AddLayer(wmsServerLayer.Name);
            }

            foreach (Client.WmsServerLayer childlayer in wmsServerLayer.ChildLayers)
            {
                AddChildLayers(childlayer, true);
            }
        }
Пример #8
0
 /// <summary>
 /// Gets all the boundingboxes from the Client.WmsServerLayer
 /// </summary>
 /// <returns>List of all spatial referenced boundingboxes</returns>
 private List<SpatialReferencedBoundingBox> getBoundingBoxes(Client.WmsServerLayer layer)
 {
     var box = new List<SpatialReferencedBoundingBox>();
     box.AddRange(layer.SRIDBoundingBoxes);
     if (layer.ChildLayers.Length > 0)
     {
         for (int i = 0; i < layer.ChildLayers.Length; i++)
         {
             box.AddRange(getBoundingBoxes(layer.ChildLayers[i]));
         }
     }
     return box;
 }
Пример #9
0
 /// <summary>
 /// Recursive method for checking whether a layername exists
 /// </summary>
 /// <param name="layer">layer</param>
 /// <param name="name">name of style</param>
 /// <returns>True of style exists</returns>
 private static bool StyleExists(Client.WmsServerLayer layer, string name)
 {
     foreach (Client.WmsLayerStyle style in layer.Style)
     {
         if (name == style.Name) return true;
     }
     foreach (Client.WmsServerLayer childlayer in layer.ChildLayers)
     {
         if (StyleExists(childlayer, name)) return true;
     }
     return false;
 }
Пример #10
0
        /// <summary>
        /// Creates an instance of this class
        /// </summary>
        /// <param name="layername"></param>
        /// <param name="wmsClient"></param>
        public WmsLayer(string layername, Client wmsClient)
        {
            _wmsClient = wmsClient;
            _continueOnError = true;

            LayerName = layername;
            //Set default mimetype - We prefer compressed formats
            if (OutputFormats.Contains("image/jpeg")) _mimeType = "image/jpeg";
            else if (OutputFormats.Contains("image/png")) _mimeType = "image/png";
            else if (OutputFormats.Contains("image/gif")) _mimeType = "image/gif";
            else //None of the default formats supported - Look for the first supported output format
            {
                bool formatSupported = false;
                foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders())
                    if (OutputFormats.Contains(encoder.MimeType.ToLower()))
                    {
                        formatSupported = true;
                        _mimeType = encoder.MimeType;
                        break;
                    }
                if (!formatSupported)
                    throw new ArgumentException(
                        "GDI+ doesn't not support any of the mimetypes supported by this WMS service");
            }
            _layerList = new Collection<string>();
            _stylesList = new Collection<string>();
        }
Пример #11
0
        private static Client GetClient(string capabilitiesUrl, IWebProxy proxy, ICredentials credentials, TimeSpan cacheTime)
        {
            Client result;
            if (!Web.HttpCacheUtility.TryGetValue("SharpMap_WmsClient_" + capabilitiesUrl, out result))
            {
                if (Logger.IsDebugEnabled)
                    Logger.Debug("Creating new client for url " + capabilitiesUrl);

                result = new Client(capabilitiesUrl, proxy, credentials);

                if (!Web.HttpCacheUtility.TryAddValue("SharpMap_WmsClient_" + capabilitiesUrl, result, cacheTime))
                {
                    if (Logger.IsDebugEnabled)
                        Logger.Debug("Adding client to Cache for url " + capabilitiesUrl + " failed");
                }
            }
            else
            {
                if (Logger.IsDebugEnabled)
                    Logger.Debug("Created client from Cache for url " + capabilitiesUrl);
            }
            return result;
        }
Пример #12
0
 /// <summary>
 /// Recursive method for checking whether a layername exists
 /// </summary>
 /// <param name="layer"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 private bool LayerExists(Client.WmsServerLayer layer, string name)
 {
     if (name == layer.Name) return true;
     foreach (Client.WmsServerLayer childlayer in layer.ChildLayers)
         if (LayerExists(childlayer, name)) return true;
     return false;
 }
Пример #13
0
        /// <summary>
        /// Recursive method for adding all WMS layers to layer list
        /// Skips "top level" layer if addFirstLayer is false
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="addFirstLayer"></param>
        /// <returns></returns>
        public void AddChildLayers(Client.WmsServerLayer layer, bool addFirstLayer)
        {
            if (addFirstLayer)
                this.AddLayer(layer.Name);
            else
                addFirstLayer = true;


            foreach (Client.WmsServerLayer childlayer in layer.ChildLayers)
            {
                AddChildLayers(childlayer, addFirstLayer);
            }
        }
Пример #14
0
        /// <summary>
        /// Initializes a new layer, and downloads and parses the service description
        /// </summary>
        /// <param name="layername">Layername</param>
        /// <param name="url">Url of WMS server</param>
        /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param>
        /// <param name="proxy">Proxy</param>
        /// <param name="credentials"></param>
        public WmsLayer(string layername, string url, TimeSpan cachetime, IWebProxy proxy, ICredentials credentials)
        {
            _capabilitiesUrl = url;
            _proxy = proxy;
            _timeOut = 10000;
            LayerName = layername;
            _continueOnError = true;
            _credentials = credentials;

            if (!Web.HttpCacheUtility.TryGetValue("SharpMap_WmsClient_" + url, out _wmsClient))
            {
                if (logger.IsDebugEnabled)
                    logger.Debug("Creating new client for url " + url);
                _wmsClient = new Client(url, _proxy, _credentials);

                if (!Web.HttpCacheUtility.TryAddValue("SharpMap_WmsClient_" + url, _wmsClient))
                {
                    if (logger.IsDebugEnabled)
                        logger.Debug("Adding client to Cache for url " + url + " failed");
                }
            }
            else
            {
                if (logger.IsDebugEnabled)
                    logger.Debug("Created client from Cache for url " + url);
            }
            /*
            if (HttpContext.Current != null && HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null)
            {
                if (logger.IsDebugEnabled)
                    logger.Debug("Creating client from Cache for url " + url);

                wmsClient = (Client)HttpContext.Current.Cache["SharpMap_WmsClient_" + url];
            }
            else
            {
                if (logger.IsDebugEnabled)
                    logger.Debug("Creating new client for url " + url);
                wmsClient = new Client(url, _Proxy, _Credentials);
                if (HttpContext.Current != null)
                    HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, wmsClient, null,
                                                     Cache.NoAbsoluteExpiration, cachetime);
            }
             */
            //Set default mimetype - We prefer compressed formats
            if (OutputFormats.Contains("image/jpeg")) _mimeType = "image/jpeg";
            else if (OutputFormats.Contains("image/png")) _mimeType = "image/png";
            else if (OutputFormats.Contains("image/gif")) _mimeType = "image/gif";
            else //None of the default formats supported - Look for the first supported output format
            {
                bool formatSupported = false;
                foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders())
                    if (OutputFormats.Contains(encoder.MimeType.ToLower()))
                    {
                        formatSupported = true;
                        _mimeType = encoder.MimeType;
                        break;
                    }
                if (!formatSupported)
                    throw new ArgumentException(
                        "GDI+ doesn't not support any of the mimetypes supported by this WMS service");
            }
            _layerList = new Collection<string>();
            _stylesList = new Collection<string>();
        }
Пример #15
0
 /// <summary>
 /// Initializes a new layer, and downloads and parses the service description
 /// </summary>
 /// <param name="layername">Layername</param>
 /// <param name="url">Url of WMS server</param>
 /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param>
 /// <param name="proxy">Proxy</param>
 public WmsLayer(string layername, string url, TimeSpan cachetime, System.Net.WebProxy proxy)
 {
     _Proxy = proxy;
     _TimeOut = 10000;
     this.LayerName = layername;
     _ContinueOnError = true;
     if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null)
     {
         wmsClient = (SharpMap.Web.Wms.Client)System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url];
     }
     else
     {
         wmsClient = new SharpMap.Web.Wms.Client(url, _Proxy);
         if (System.Web.HttpContext.Current != null)
             System.Web.HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, wmsClient, null,
                 System.Web.Caching.Cache.NoAbsoluteExpiration, cachetime);
     }
     //Set default mimetype - We prefer compressed formats
     if (OutputFormats.Contains("image/jpeg")) _MimeType = "image/jpeg";
     else if (OutputFormats.Contains("image/png")) _MimeType = "image/png";
     else if (OutputFormats.Contains("image/gif")) _MimeType = "image/gif";
     else //None of the default formats supported - Look for the first supported output format
     {
         bool formatSupported = false;
         foreach (System.Drawing.Imaging.ImageCodecInfo encoder in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders())
             if (OutputFormats.Contains(encoder.MimeType.ToLower()))
             {
                 formatSupported = true;
                 _MimeType = encoder.MimeType;
                 break;
             }
         if (!formatSupported)
             throw new ArgumentException("GDI+ doesn't not support any of the mimetypes supported by this WMS service");
     }
     _LayerList = new Collection<string>();
     _StylesList = new Collection<string>();
 }
Пример #16
0
        /// <summary>
        /// Initializes a new layer, and downloads and parses the service description
        /// </summary>
        /// <param name="layername">Layername</param>
        /// <param name="url">Url of WMS server's Capabilities</param>
        /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param>
        /// <param name="proxy">Proxy</param>
        public TiledWmsLayer(string layername, string url, TimeSpan cachetime, WebProxy proxy)
        {
            _Proxy = proxy;
            _TimeOut = 10000;
            LayerName = layername;
            _ContinueOnError = true;

            if (!Web.HttpCacheUtility.TryGetValue("SharpMap_WmsClient_" + url, out _WmsClient))
            {
                if (logger.IsDebugEnabled)
                    logger.Debug("Creating new client for url " + url);
                _WmsClient = new Client(url, _Proxy, _Credentials);

                if (!Web.HttpCacheUtility.TryAddValue("SharpMap_WmsClient_" + url, _WmsClient))
                {
                    if (logger.IsDebugEnabled)
                        logger.Debug("Adding client to Cache for url " + url + " failed");
                }
            }
            _TileSets = TileSet.ParseVendorSpecificCapabilitiesNode(_WmsClient.VendorSpecificCapabilities);
        }
Пример #17
0
        /// <summary>
        /// Recursive method for checking whether a layername exists
        /// </summary>
        /// <param name="wmsServerLayer">The WMS Server layer</param>
        /// <param name="name">The name of the desired layer</param>
        /// <returns></returns>
        private static bool LayerExists(Client.WmsServerLayer wmsServerLayer, string name)
        {
            if (name == wmsServerLayer.Name)
            {
                return true;
            }

            foreach (Client.WmsServerLayer childlayer in wmsServerLayer.ChildLayers)
            {
                if (LayerExists(childlayer, name)) return true;
            }
            return false;
        }