ThinkGeo.com    |     Documentation    |     Premium Support

Showing data from a WMS-service

Hi,

there are examples in the “HowDoI”-solution how to integrate a WMS-service, unfortunately the example-uri references are not reachable. Is there any working example of how to integrate a WMS, maybe using a public WMS-feature?

Any help is appreciated.

Regards,
Andreas

Hi Andreas,

Because some reason we hadn’t put a sample in wiki shows how to use the WMS server. But you can use that like this:

WmtsLayer wmtsLayer = new WmtsLayer(new Collection { new Uri(“your link”) });
wmtsLayer.Parameters.Add(“LAYER”, “your layer”);
wmtsLayer.Parameters.Add(“STYLE”, “default”);
wmtsLayer.Parameters.Add(“FORMAT”, “image/png”);

        var overlay = new LayerOverlay();
        overlay.Layers.Add(wmtsLayer);
        wpfMap1.Overlays.Add(overlay);

Which parameter need be added is decided by the WMS server you want to connectted, you can get the parameters from the capability, or you can use the event wmtsLayer.SendingWebRequest to double check whether the request url for tile is works for your WMS server.

Regards,

Don

Hi Don,

when i put your code in my Map-Loaded-method, i get an exception at runtime:

System.ArgumentNullException wurde nicht behandelt.
Message: Ein Ausnahmefehler des Typs “System.ArgumentNullException” ist in WpfDesktopEdition.dll aufgetreten.
Zusätzliche Informationen: Der Wert darf nicht NULL sein.

Regards,
Andreas

Hi Andreas,

You should want to modify the url and paramters follow your WMS server.

Could you please show the exception in English, it looks I cannot understand what’s the exception shows. And please paste your test code also.

Regards,

Don

Hi Don,

here is my example-code.

        TiledWmsLayer wmsLayer = new TiledWmsLayer(new List<Uri>() { new Uri("https://geoserver.sfei.org/prd/sfeiwebservices/wms") });
        wmsLayer.Parameters.Add("LAYER", "cramaas");
        wmsLayer.Parameters.Add("FORMAT", "image/png");
        var overlay = new LayerOverlay();
        overlay.Layers.Add(wmsLayer);
        wpfMap1.Overlays.Add(overlay);

I use a public WMS-server just for testing, i keep getting this error:
System.ArgumentException:The Wms request LAYERS parameter is missing.

What am i doing wrong?

Regards,
Andreas

Hi Andreas,

The code as below should works for you.

private void WpfMap_Loaded(object sender, RoutedEventArgs e)
{
Map1.MapUnit = GeographyUnit.DecimalDegree;
Map1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

        TiledWmsLayer wmsLayer = new TiledWmsLayer(new List<Uri>() { new Uri("https://geoserver.sfei.org/prd/sfeiwebservices/wms") });            
        wmsLayer.ActiveLayerNames.Add("cramaas");            
        wmsLayer.Parameters.Add("FORMAT", "image/png");
        var overlay = new LayerOverlay();
        overlay.Layers.Add(wmsLayer);
        Map1.Overlays.Add(overlay);

        Map1.CurrentExtent = new RectangleShape(-124, 42, -115, 32);

        Map1.Refresh();
    }

And you can get more information here:
https://geoserver.sfei.org/prd/sfeiwebservices/wms?SERVICE=WMS&REQUEST=GetCapabilities

Regards,

Don

Hi Don,

thanks, it works now.

Regards,
Andreas

Hi Andreas,

I am glad to hear that works.

Regards,

Don