This project has moved and is read-only. For the latest updates, please go here.

Problem with WMS layer

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Sep 15, 2010 at 3:51 PM


I am having some dificulties with a WMS layer from this url

I think that is because the layers doen´t have its own BoundingBox, as it can be seen in the xml information.


- <!--   -->
 WARNING: Optional Ex_GeographicBoundingBox could not be established for this layer.  Consider setting the EXTENT in the LAYER object, or wms_extent metadata. Also check that your data exists in the DATA statement 
Any help?,
Here is the code I´ve been using, It works perfectly with other data from others servers.

String^ wmsUrl =


SharpMap::Layers::WmsLayer^layWms_GZK =

gcnew SharpMap::Layers::WmsLayer("Gipuzkoa WMS", wmsUrl);

SharpMap::Web::Wms::Capabilities::WmsServiceDescription^ServiceDescription_s = layWms_GZK->ServiceDescription;

System::String^ imageUrlServicios=ServiceDescription_s->OnlineResource+


layWms_GZK->SpatialReferenceSystem =


layWms_GZK->SRID = 23030;






layWms_GZK->ContinueOnError =


layWms_GZK->TimeOut = 5000;

//Set timeout to 5 seconds


// BBOX //


float minx=530000,miny=4740000,maxx=610000,maxy=48200000;

SharpMap::Geometries::BoundingBox^LatLonBox = LatLonBox =

gcnew SharpMap::Geometries::BoundingBox(minx,miny,maxx,maxy);



// MAPA //

System::Drawing::Size size_map= System::Drawing::Size(10,10);

SharpMap::Map^map =

gcnew SharpMap::Map(size_map);

map->Size = pictureBox_Imag->Size;







// Imagen
<!-- f(clean); // -->
Sep 16, 2010 at 4:03 PM
Edited Sep 16, 2010 at 4:09 PM

Ah, managed c++ leetness :)

The invididual ortho layers can only be requeste in epsg 23030, so you have to set the layer's SRID to 23030. In your code you use root layer 'gipuzkoa_wms' this will cause the WMS to return all layers stacked on top of each other, this will be slow and is probably not what you want. In the sample I request only orto2009. I also committed a bug fix in parsing the latlonboundingbox. You may have run into this, but this is not the actual solution to your problem.

If you replace the WmSample of the WinFormsSamples project with the code below you can view the orto2009 layer

using System.Drawing;
using SharpMap;
using SharpMap.Layers;

namespace WinFormSamples.Samples
    public static class WmsSample
        public static Map InitializeMap()
            string wmsUrl = "";

            Map map = new Map();

            WmsLayer layWms = new WmsLayer("Demis Map", wmsUrl);


            layWms.ContinueOnError = true;
                //Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
            layWms.TimeOut = 5000; //Set timeout to 5 seconds
            layWms.SRID = 23030;

            map.BackColor = Color.White;


            return map;
Sep 16, 2010 at 4:52 PM


First of all thank you for yor help, I have tried your code, and still can´t see the map. It have crashed in map.ZoomToExtents(); having this msg  

Excepción no controlada del tipo 'System.NullReferenceException' en SharpMap.dll

Información adicional: Referencia a objeto no establecida como instancia de un objeto.

If I comment this sentence we only see the background color. I don´t know what am I doing wrong, I attach the code I´ve used.


String^ wmsUrl ="";

SharpMap::Map^map =gcnew SharpMap::Map();

SharpMap::Layers::WmsLayer^layWms = gcnew SharpMap::Layers::WmsLayer("Demis Map", wmsUrl);



layWms->ContinueOnError = true;

layWms->TimeOut = 5000; //Set timeout to 5 seconds

layWms->SRID = 23030;


map->BackColor = Color::Blue;


pictureBox->Image=map->GetMap();// Imagen


Sep 16, 2010 at 11:30 PM

You code seems correct. Perhaps you don't have the most recent version from the trunk? Do you add any other layers?

If problems persist you could first try my sample code just in c#. Download the latest version from the trunk, go to the WinFormsSamples project, and to the WmsSample class and paste the code in. If that works convert the c# code into a simple managed c++ sample.

In general it is advised to include the source code in your project and step through it. The code is fairly readable. 




Sep 27, 2010 at 11:44 AM

Thanks for your help. works perfectly.

Oct 5, 2010 at 3:25 PM
Edited Oct 18, 2010 at 8:46 PM

Hi pauldendulk,

I am working on WMs layers but not able to get it layers only blue background is coming.

I want to use openalayers WMs layers , as you can see in my code.

Please help me to get it fix.




Oct 5, 2010 at 3:59 PM


The WMS server maps are not accessible. The name of the layers can be seen, but no information is displayed.

I leave an address where you can access the maps. Layer "Catastro" has data for Spain.

I hope you serve.


  This code gets the name of the WMS server layers and copy the file c: \ \ capas.txt

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SharpMap;
using SharpMap.Layers;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1(){InitializeComponent();}
        private void pictureBox1_Click(object sender, EventArgs e){}
        private void Form1_Load(object sender, EventArgs e)
            string wmsUrl = "";
            /////// Layer
            WmsLayer layWms = new WmsLayer("Demis Map", wmsUrl);
            /////// Mostramos las capas
            System.IO.StreamWriter sw_html= new System.IO.StreamWriter("c:\\capas.txt",false,System.Text.Encoding.Default);
		    SharpMap.Web.Wms.Client.WmsServerLayer LayerServ=layWms.RootLayer;
			int Num=LayerServ.ChildLayers.Length;
		    for(int y=0;y<Num;y++)
			    SharpMap.Web.Wms.Client.WmsServerLayer childlayer=LayerServ.ChildLayers[y];
			    String NomCapa_s=childlayer.Title;
			    String NomMap_s=childlayer.Name;



Oct 5, 2010 at 4:39 PM
Edited Oct 18, 2010 at 8:47 PM

Hi  thanks for your reply.


but still it's not woking i am geeting text file in d drive with values. 

but i am getting light blue screen only not map.


Oct 6, 2010 at 8:28 AM
I hope you serve.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SharpMap;
using SharpMap.Layers;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1() { InitializeComponent(); }
        private void pictureBox1_Click(object sender, EventArgs e) { }
        private void Form1_Load(object sender, EventArgs e)
            //===== WmsLayer  =====//
	        string wmsUrl2 = "";
	        SharpMap.Layers.WmsLayer layWms_CyL = new SharpMap.Layers.WmsLayer("CYL WMS", wmsUrl2);
	        SharpMap.Web.Wms.Capabilities.WmsServiceDescription ServiceDescription_CyL = layWms_CyL.ServiceDescription;
            // URL where is the description of the wms server services
            string imageUrlServicios_CyL = ServiceDescription_CyL.OnlineResource + "?REQUEST=GetCapabilities&SERVICE=WMS";
            // projection system of the server layers. Very important because in this case is EPSG: 4326, but yours may be different.
            layWms_CyL.SpatialReferenceSystem ="EPSG:4326";
	        layWms_CyL.SRID = 4326;
            // Layer 
            // Image format returned by the server. You have to check which supports.
	        layWms_CyL.SetImageFormat(layWms_CyL.OutputFormats[1]); // Format jpg,png....
	        layWms_CyL.ContinueOnError = true; //Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
	        layWms_CyL.TimeOut = 5000; //Set timeout to 5 seconds
            //BBox -. Very important to map the boundaries of the coordinate system we have specified.
	        double minx=40.066933,miny=-6.969119,maxx=43.17745,maxy=-2.37922;
	        SharpMap.Geometries.BoundingBox LatLonBoxLayerCyL= new SharpMap.Geometries.BoundingBox(minx,miny,maxx,maxy);
        	 //===== map  =====//
            SharpMap.Map map = new SharpMap.Map(new Size(400, 300));;
	        map.BackColor = Color.Blue;
	        map.Size =this.pictureBox1.Size; 
            // Add layer
	        // Center
            SharpMap.Geometries.Point Point = map.ImageToWorld(new PointF(this.pictureBox1.Width / 2, this.pictureBox1.Height / 2));
            map.Center = Point;
	        // Picture	
	        this.pictureBox1.Image=map.GetMap();// Picture
Oct 6, 2010 at 3:04 PM

Thanks it worked,

Oct 6, 2010 at 3:07 PM

Hi Automatica,

I have one question in my mind. I need to have markers and data  will come from Excel sheet.

how we can do this, do you have any code example for this.


Thanks in advance.

Vivek Kumar

Oct 6, 2010 at 4:54 PM


I get the data from a SQL Server DB. From Excel I have not ever made and do not be mean.


Oct 6, 2010 at 5:00 PM

Hi Automatica,

Sorry for the confusion, actually I want to browse data from from excel then I will save in database then I will load to map.


Vivek Kumar


Oct 6, 2010 at 9:03 PM
hello. I am Spanish and translation if not need position multiple points of latitude and longitude on the map?
Oct 7, 2010 at 9:40 AM


Hi Automatica,

Just want to know how I can put markers on map. I mean one Image based upon latitude and longitude.

Please let me know any code sample.

Thanks for your time.

Vivek Kumar

Oct 7, 2010 at 10:15 AM

Hi Vivek Kumar.

SharMap the library but I have not.
I have with different library examples.

 If you want this, give me your email and  send.


Oct 8, 2010 at 12:58 PM