ThinkGeo.com    |     Documentation    |     Premium Support

Use Custom WMS feeds

Hi,

Could not find a sample for using custom WMS feed, could you please refer me to a sample or add a smaple for using custom WMS layer of WPF project?

Hi Behnam,

We have two class is related with that: TiledWmsLayer and wmsoverlay

Sorry we don’t have a sample for them but I think you can search that in our forum with the keyword.

You should want to read the capability of target WMS server and add the important parameters.

The code should looks like:

TiledWmsLayer tiledWmsLayer = new TiledWmsLayer(new Uri(ConfigurationManager.AppSettings[“WMSServer”]));
tiledWmsLayer.ActiveLayerNames.Add("");
tiledWmsLayer.ActiveStyleNames.Add("");

Wish that’s helpful.

Regards,

Don

Hi Don,

Many thanks for your reply, I have tried
http://irs.gis-lab.info/?layers=osm&
which works find in QGis but I get following exception

at ThinkGeo.MapSuite.WpfDesktopEdition.Tile.<>c__DisplayClass5.b__3()
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

my code is:

     var layer = new TiledWmsLayer(new List<Uri> { new Uri(_settings.CustomUri) });
     return new LayerOverlay(new BindingList<Layer> { layer

Regards,
Behnam

Hi Behnam,

As below is a workaround, it looks your server forbidden request the area out of limitation.

TiledWmsLayer layer = new TiledWmsLayer();
layer.ServerUris.Add(new System.Uri(“http://irs.gis-lab.info”));
layer.ActiveLayerNames.Add(“osm”);
layer.SendingWebRequest += Layer_SendingWebRequest;

        LayerOverlay overlay = new LayerOverlay();
        overlay.Layers.Add(layer);
        Map1.Overlays.Add(overlay);

        Map1.CurrentExtent = new RectangleShape(-60, 50, 60, -50);
        
        Map1.Refresh();




     private void Layer_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
    {
        string requestURL = e.WebRequest.RequestUri.ToString();
        if (requestURL.Contains("BBOX"))
        {
            int bboxstartindex = requestURL.IndexOf("BBOX=") + 5;
            int bboxendindex = requestURL.IndexOf("&", bboxstartindex);

            double maxx = 180;
            double minx = -180;
            double maxy = 85.0511287798;
            double miny = -85.0511287798;

            string bbox = requestURL.Substring(bboxstartindex, bboxendindex - bboxstartindex);
            string[] xy = bbox.Split(',');

            if (xy.Length == 4)
            {
                double requestmaxx = double.Parse(xy[2]);
                double requestminx = double.Parse(xy[0]);
                double requestmaxy = double.Parse(xy[3]);
                double requestminy = double.Parse(xy[1]);

                if (requestmaxx > maxx)
                {
                    requestmaxx = maxx;
                }

                if (requestminx < minx)
                {
                    requestminx = minx;
                }

                if (requestmaxy > maxy)
                {
                    requestmaxy = maxy;
                }

                if (requestminy < miny)
                {
                    requestminy = miny;
                }

                string newBBOX = string.Format("{0},{1},{2},{3}", requestminx, requestminy, requestmaxx, requestmaxy);

                string newRequestURL = requestURL.Replace(bbox, newBBOX);

                e.WebRequest = HttpWebRequest.Create(newRequestURL);
            }
        }
    }

Regards,

Don

Hi,

Many thanks for your reply, I have created a sample project with a shape and wms layer(s).

if the WMS is Bing it shows everything fine but if you switch to OSM it will not show the background and only show exception-tiles.

ps: to look at bing you need bing key.CustomWMS.zip (42.5 KB)

Hi Behnam,

The BingMap is under projection 3857 and the map unit is meter, your WMS server is under 4326 and map unit is decimal degree.

Please set the correct mapunit and Proj4Projection parameter, then you can get the correct result.

Regards,

Don

Many thanks for your reply

Hi Behnam,

I am glad to hear that’s helpful.

Regards,

Don