ThinkGeo.com    |     Documentation    |     Premium Support

Add WMS Overlay / Layer does not work

Hi, I am trying to add a WMS Overlay or Layer. However, neither gives me an expected result.

Within the HowDoI Application, I have adapted the Overlay to be like this:

        private void UseOverlay()
    {
        // Clear out the overlays so we start fresh
        MapView.Overlays.Clear();

        // Create a WMS overlay using the GetCapabilities URL.
        var wmsOverlay = new WmsOverlay
        {
            Uri = new Uri("https://sgx.geodatenzentrum.de/wms_basemapde?REQUEST=GetCapabilities&Version=1.3.0&SERVICE=WMS")
        };

        wmsOverlay.ActiveLayerNames.Add("de_basemapde_web_raster_farbe");
        wmsOverlay.Parameters.Add("FORMAT", "image/png");
        wmsOverlay.Parameters.Add("CRS", "EPSG:3857");

        // Add the overlay to the map.
        MapView.Overlays.Add(wmsOverlay);
    }

However, this returns me a white box:

https://sgx.geodatenzentrum.de/wms_basemapde?REQUEST=GetCapabilities&Version=1.3.0&SERVICE=WMS

Can you please help me how to get this to work? If you need any additional information please dont hesitate to ask, as I am new to working with WMS.

Thanks!

I have tried this with a different WMS Service and it still does not work.
I have read the Layers from the Server using this: wmsOverlay.GetServerLayers()
This works and returns me the two layers existing in this Service.
I then added one of the two layer names to my function as displayed below. This, however, only gives me a white square again, same result as above.

private void UseOverlay()
{
    // Clear out the overlays so we start fresh
    MapView.Overlays.Clear();

    // Create a WMS overlay using the GetCapabilities URL.
    var wmsOverlay = new WmsOverlay
    {
        Uri = new Uri("https://www.lfu.bayern.de/gdi/wms/boden/buek200by?")
    };

    wmsOverlay.ActiveLayerNames.Add("buek200");

    // Add the overlay to the map.
    MapView.Overlays.Add(wmsOverlay);
}

Inspecting the HttpMessage (like this) returns the following:

Debug Output:

https://www.lfu.bayern.de/gdi/wms/boden/buek200by?SERVICE=WMS&REQUEST=GetCapabilities

https://www.lfu.bayern.de/gdi/wms/boden/buek200by?REQUEST=GetMap&BBOX=-180,-270.6505430128364,180.6505430128364,90&WIDTH=512&HEIGHT=512&LAYERS=buek200&STYLES=default&FORMAT=image/png&CRS=EPSG:3857&VERSION=1.3.0&SERVICE=WMS

hi @Julian_Thoms,

It seems that the first WMS doesn’t work with EPSG:3857, we need to use CRS:84. You could try the following code.

I think there’s something wrong with the second WMS, either ThinkGeo or QGIS cannot work with it. Did you get it working with other GIS tools?

        MapView.MapUnit = GeographyUnit.DecimalDegree;

        // Create a WMS overlay using the GetCapabilities URL.
        var wmsOverlay = new WmsOverlay
        {
            Uri = new Uri("https://sgx.geodatenzentrum.de/wms_basemapde?REQUEST=GetCapabilities&Version=1.3.0&SERVICE=WMS")
        };

        wmsOverlay.ActiveLayerNames.Add("de_basemapde_web_raster_farbe");
        // use Property OutputFormat instead of Parameters.Add("FORMAT", "image/png");
        wmsOverlay.OutputFormat = "image/png";
        // use Property Crs instead of Parameters.Add("CRS", "xxxx");
        wmsOverlay.Crs = "CRS:84";

        // Add the overlay to the map.
        MapView.Overlays.Add(wmsOverlay);

        wmsOverlay.SendingHttpRequest += WmsOverlay_SendingHttpRequest;
        await wmsOverlay.OpenAsync();
        MapView.CurrentExtent = wmsOverlay.GetBoundingBox();

        await MapView.RefreshAsync();

Regards,
Leo

Hi Leo, thank you very much for your response.

We got it to work with ESRI ArcGIS Pro 3.4.2 like this:

Add Data -> Path -> Add the url as a path and “WMS OGC Web Service” as Service Type

I will try your suggestion and report back. However, we would like to offer a simple url dropin tool so that a custom WMS can be displayed. I thought that I can simply use the in the Capabilities mentioned EPSG / let the User pick one of those options, however this does not seem to work with ThinkGeo then? Or is that a WMS issue?

Hi Leo, I have tried your suggested code and got it to work - however, it is very warped, see:

Using ESRI ArcGIS Pro, adding it with the correct EPSG (25832) was no issue. However, when trying the same thing with ThinkGeo, it shows me the following Screen:

private async Task UseOverlay()
{
    Debug.WriteLine("Use overlay selected");
    // Clear out the overlays so we start fresh
    MapView.Overlays.Clear();

    // Create a WMS overlay using the GetCapabilities URL.
    var wmsOverlay = new WmsOverlay
    {
        Uri = new Uri("https://sgx.geodatenzentrum.de/wms_basemapde?REQUEST=GetCapabilities&Version=1.3.0&SERVICE=WMS")
    };

    wmsOverlay.ActiveLayerNames.Add("de_basemapde_web_raster_farbe");
    // use Property OutputFormat instead of Parameters.Add("FORMAT", "image/png");
    wmsOverlay.OutputFormat = "image/png";
    // use Property Crs instead of Parameters.Add("CRS", "xxxx");
    wmsOverlay.Crs = "EPSG:25832";

    // Add the overlay to the map.
    MapView.Overlays.Add(wmsOverlay);

    wmsOverlay.SendingHttpRequest += WmsOverlay_SendingHttpRequest;

    await wmsOverlay.OpenAsync();
    MapView.CurrentExtent = wmsOverlay.GetBoundingBox();

    await MapView.RefreshAsync();
}

Also, it does not seem to make an API call at all, as I do not get any output in the Debug output, neither from the SendingHttpRequest nor from the ThinkGeoDebugger which is set to “All”.

hi @Julian_Thoms,

I tried EPSG:25832 and it worked good. Here’s the sample WmsSample.zip (3.5 KB) , feel free to give it try. One thing to note is that the map size should not be too small, it appeared blank when the map size was 450 x 800, but it worked with a map size of 750 x 1200.

Regarding the EPSG options in capabilities, you could call wmsOverlay.GetServerCrsCollection() to get all the EPSG mentioned in capabilities xml.

Regards,
Leo