ThinkGeo.com    |     Blog    |     Wiki    |     Support

Loading WMS as WmsRasterLayer

Hi all,

I like to load two WMS layers. But which parameters do I set to get a map?
Here are the URLs

Flurkarte: http://www.geoportal.rlp.de/mapbender/php/wms.php?layer_id=24123&VERSION=1.1.1&

Luftbilder: http://www.geoportal.rlp.de/mapbender/php/wms.php?layer_id=30692&VERSION=1.1.1&withChilds=1

Need the parameters load as WmsRasterLayer.

Hope you can help with a snippet.

Regards
Hardy

Hi Hardy,

As below is the capability for your server:
http://www.geoportal.rlp.de/mapbender/php/wms.php?layer_id=24123&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities
http://www.geoportal.rlp.de/mapbender/php/wms.php?layer_id=30692&VERSION=1.1.1&withChilds=1&SERVICE=WMS&REQUEST=GetCapabilities

You can find necessary parameter from the capability.

You can see your wms server is a little special, because it contains a layer_id even when get capability.
So we solve it by the sending request event.

Here is my test code for your first server:

            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

        WmsRasterLayer wmsRaster = new WmsRasterLayer(new Uri("http://www.geoportal.rlp.de/mapbender/php/wms.php"));

        wmsRaster.SendingWebRequest += WmsRaster_SendingWebRequest;            
        wmsRaster.ActiveLayerNames.Add("rlp:rlp");            
        wmsRaster.Crs = "EPSG:4326";            
        wmsRaster.OutputFormat = "image/png";            
        

        wmsRaster.Open();


        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(wmsRaster);


        winformsMap1.Overlays.Add(layerOverlay);
        winformsMap1.CurrentExtent = wmsRaster.GetBoundingBox();
        winformsMap1.Refresh();

And you need handle the request url here:

        private void WmsRaster_SendingWebRequest(object sender, SendingWebRequestEventArgs e)
    {
        e.WebRequest = HttpWebRequest.Create(e.WebRequest.RequestUri.ToString() + "&layer_id=24123");\

        Debug.WriteLine(e.WebRequest.RequestUri.ToString());
    }

Generally the default style have to be set, but your server don’t have style, so we ignore it.

Now the layer can require a tile, but it still don’t works because srever return a blank image without exception information. Here is the url:

http://geo4.service24.rlp.de/wms/lika_basis.fcgi?REQUEST=GetMap&BBOX=5.19938265625,48.4650854492187,9.37418734375,51.4149145507812&WIDTH=760&HEIGHT=537&LAYERS=rlp:rlp&STYLES=&FORMAT=image/png&SRS=EPSG:4326&VERSION=1.1.1&SERVICE=WMS&EXCEPTIONS=application/vnd.ogc.se_xml&layer_id=24123

Here I think you have to try modify the paramter to get a valid tile, or asked server provider to get a valid GetMap url. And then you can modify the parameter in layer to make it works.

You can also do the same things for your 2nd server, please notice each custom paramter after “?” have to be handled in SendingWebRequest event if it also be used when require capability, if it only be used in Getmap but not in Getcapabilities, you can add them like this:

wmsRaster.Parameters.Add(“layer_id”, “xxxxx”);

Wish that’s helpful.

Regards,

Ethan

Hi Ethan,

I have add one more parameter:
wmsLayer.Exceptions = “INIMAGE”

Now it’s working fine.

Regards
Hardy

Hi Hardy,

I am glad to hear it works and thanks for your update.

Regards,

Ethan