This project has moved. For the latest updates, please go here.

How do I add a WMS layer?

The WMS Layer support is currently pretty basic. You will have to decipher the server capabilities yourself, and specify the nessesary layers and other properties in the resource property.

Here's an example of how to add the Demis WMS server:
string wmsUrl = "";
SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Demis Map", wmsUrl);
layWms.SpatialReferenceSystem = "EPSG:4326"; //Set spatial reference to use for this service

//Add layers (browse the RootLayer/ChildLayers collection to find available/valid layer names)
layWms.AddLayer("Ocean features");

//Set image format to request from server
//See layWms.OutputFormats array for formats supported by this WMS
//Skip rendering the WMS Map if the server couldn't be requested
//If set to false such an event would crash the app.
layWms.ContinueOnError = true;
layWms.TimeOut = 5000; //Set timeout to 5 seconds

myMap.Layers.Add(layWms); //Add layer to your map's layer collection

You can get an example of how an image request would look like, by using the GetRequestUrl method. This is also good for debugging the WMS server, since the server often returns an error message on invalid requests.
// Note: 
// The constructor for GeoAPI.Geometries.Envelope takes (xmin, xmax, ymin, ymax)
// instead of (xmin, ymin, xmax, ymax) that old BoundingBox did.
string imageUrl = layWms.GetRequestUrl(new GeoAPI.Geometries.Envelope(0,360,0,180), new Size(600,300));

Last edited Aug 31, 2012 at 11:49 AM by FObermaier, version 6