Problem with WMS layer

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

Hello

I am having some dificulties with a WMS layer from this url http://b5m.gipuzkoa.net/ogc/wms/gipuzkoa_wms?REQUEST=GetCapabilities&SERVICE=WMS

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

<CRS>EPSG:23030</CRS>

- <!--   -->
 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 =

"http://b5m.gipuzkoa.net/wms/gipuzkoa_wms";

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+

"REQUEST=GetCapabilities&SERVICE=WMS";

layWms_GZK->SpatialReferenceSystem =

"EPSG:23030";

layWms_GZK->SRID = 23030;

layWms_GZK->AddLayer(

"gipuzkoa_wms");

layWms_GZK->AddLayer(

"udal_barrutiak_limites_municipales");

layWms_GZK->SetImageFormat(layWms_GZK->OutputFormats[0]);

layWms_GZK->ContinueOnError =

true;

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;

 

//map->Layers->Add(layWms_CyL);
 

map->Layers->Add(layWms_GZK);

map->ZoomToBox(LatLonBox);

//map->ZoomToExtents();

pictureBox_Imag->Image=map->GetMap();

// Imagen
<!-- f(clean); // -->
Developer
Sep 16, 2010 at 3:03 PM
Edited Sep 16, 2010 at 3: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 = "http://b5m.gipuzkoa.net/wms/gipuzkoa_wms";

            Map map = new Map();

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

            layWms.AddLayer("orto2009");

            layWms.SetImageFormat(layWms.OutputFormats[0]);
            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.Layers.Add(layWms);

            map.BackColor = Color.White;

            map.ZoomToExtents();

            return map;
        }
    }
}
Sep 16, 2010 at 3:52 PM

Hello

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.

Regards.

String^ wmsUrl ="http://b5m.gipuzkoa.net/wms/gipuzkoa_wms";

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

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

layWms->AddLayer("orto2009");

layWms->SetImageFormat(layWms->OutputFormats[0]);

layWms->ContinueOnError = true;

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

layWms->SRID = 23030;

map->Layers->Add(layWms);

map->BackColor = Color::Blue;

map->ZoomToExtents();

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

 

Developer
Sep 16, 2010 at 10: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. 

Paul

 

 

Sep 27, 2010 at 10:44 AM

Thanks for your help. works perfectly.

Oct 5, 2010 at 2:25 PM
Edited Oct 18, 2010 at 7: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 2:59 PM

Hello.

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.

http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx

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 = " http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx";
            /////// 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;
               layWms.AddLayer(NomMap_s);
                sw_html.WriteLine(NomMap_s);
		    }
            sw_html.Close();
        }

    }
}

 

Oct 5, 2010 at 3:39 PM
Edited Oct 18, 2010 at 7: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 7: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 = "http://www.idecyl.jcyl.es/services/MedioAmbiente/sigmena/MapServer/WMSServer?";
	        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 
            layWms_CyL.AddLayer("0");
            // 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
	    	map.Layers.Add(layWms_CyL);
	        //zoom
	        map.ZoomToBox(LatLonBoxLayerCyL);
	        // 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 2:04 PM

Thanks it worked,

Oct 6, 2010 at 2: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 3:54 PM

Hello.

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

Sorry

Oct 6, 2010 at 4: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.

Thanks,

Vivek Kumar

 

Oct 6, 2010 at 8:03 PM
hello. I am Spanish and translation if not good.you need position multiple points of latitude and longitude on the map?
Oct 7, 2010 at 8: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 9: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 11:58 AM

it's vivek.kumar@r2international.com