Map server URL with help of WMS layer

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, WinForms Controls
Nov 30, 2010 at 5:03 PM

Hi Felix,

I am using map server URL with help of WMS layer .

 
                ////Map Server URL 
                string wmsUrl = "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1-map.map&layer=states&mode=map";
                WmsLayer layWms = new WmsLayer("states", wmsUrl);

                layWms.AddLayer("states");
                layWms.SetImageFormat(layWms.OutputFormats[3]);

                //Map Server Transparancy 
                layWms.Transparancy = true;           
                layWms.SetImageFormat("image/png");
                layWms.ContinueOnError = true;
                layWms.BgColor = System.Drawing.Color.Transparent;
                //Set timeout to 5 seconds
                layWms.TimeOut = 5000;

                //Map Server Projection ID
                layWms.SRID = 4326;

                map.Layers.Add(layWms);

I am getting this error Could not download capabilities  in this line 

WmsLayer layWms = new WmsLayer("states", wmsUrl); 
I can run this http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map&layer=states&mode=map
in my browser and i am getting map. but not with help of sharp map.
please let me know whether this is possible in sharp map or not?
if it is please guide me .

thanks for the help.
Coordinator
Nov 30, 2010 at 8:54 PM

Hello vivek,

according to http://mapserver.org/ogc/wms_server.html you need to reduce your url to

http://localhost/cgi-bin/mapserv.exe?

Hth FObermaier

Dec 1, 2010 at 7:38 AM

Hi FObermaier,

Thanks for the reply! but I want to show the map shapefile by using above URL . 

how I have to place the URL and how I have to call with sharmpap wms layer. and how I can call shapefile with help of map server,

could you please guide me.

thanks for the help.

thanks again,

Dec 1, 2010 at 8:25 AM

Hi FObermaier,

I want to show shapefile saved in my local hardrive with help of map server URL.

is it possible in sharmap?

please guide me. I searched a lot and I am not getting anything.

thanks for the help.

 

Coordinator
Dec 1, 2010 at 8:34 AM

Hello vivek,

I think, Wms layer works like this:

string const wmsUrl = "http://localhost/cgibin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1-map.map&";

Map map = new Map();

WmsLayer layWms = new WmsLayer("VIVEK's Map", wmsUrl);

layWms.AddLayer("states");

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 = 4326; map.Layers.Add(layWms);

If it does not, try the step by step debugger and post the stack trace and variable values where it fails

Hth FObermaier

Dec 1, 2010 at 8:55 AM

Hi FObermaier,

no FObermaier still not working. 

if I want to have shape file to map file in URL .

what would be the best approach.

Thanks for the help.

 

Coordinator
Dec 1, 2010 at 9:31 AM
Edited Dec 1, 2010 at 9:43 AM

Vivek,

try removing the '&' at the end of the url:

string const wmsUrl = "http://localhost/cgibin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1-map.map";
Dec 1, 2010 at 9:52 AM

Hi FObermaier,

thanks for the reply. 

but still it;'s showing up "Could not download capabilities" at the line  WmsLayer layWms = new WmsLayer("MyMap", wmsUrl);

Please let me know what else I can do. I tried each and every solutions and it's not working.

Please guide me to achieve this.

Thanks for the support.


Coordinator
Dec 1, 2010 at 10:14 AM

Please post full stack trace

Dec 1, 2010 at 10:20 AM

Hi ,

thanks for the reply.

Please find full details.

System.ApplicationException was unhandled  Message=Could not download capabilities  Source=SharpMap  StackTrace:       at SharpMap.Web.Wms.Client.GetRemoteXml(String Url, WebProxy proxy)       at SharpMap.Web.Wms.Client..ctor(String url, WebProxy proxy)       at SharpMap.Layers.WmsLayer..ctor(String layername, String url, TimeSpan cachetime, WebProxy proxy)       at SharpMap.Layers.WmsLayer..ctor(String layername, String url, TimeSpan cachetime)       at SharpMap.Layers.WmsLayer..ctor(String layername, String url)       at WinFormSamples.WMSclient.InitializeMap() in C:\Documents and Settings\user\My Documents\My Dropbox\r2_vivek_ville\New Folder\WMSClient - Copy (2) - Copy\WMSclient.cs:line 73       at WinFormSamples.WMSclient..ctor() in C:\Documents and Settings\user\My Documents\My Dropbox\r2_vivek_ville\New Folder\WMSClient - Copy (2) - Copy\WMSclient.cs:line 52       at WinFormSamples.frmTest.InitializeComponent() in C:\Documents and Settings\user\My Documents\My Dropbox\r2_vivek_ville\New Folder\WMSClient - Copy (2) - Copy\frmTest.designer.cs:line 31       at WinFormSamples.frmTest..ctor() in C:\Documents and Settings\user\My Documents\My Dropbox\r2_vivek_ville\New Folder\WMSClient - Copy (2) - Copy\frmTest.cs:line 25       at WinFormSamples.Program.Main() in C:\Documents and Settings\user\My Documents\My Dropbox\r2_vivek_ville\New Folder\WMSClient - Copy (2) - Copy\Program.cs:line 16       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStart()  InnerException: System.Net.WebException       Message=The remote server returned an error: (404) Not Found.       Source=System       StackTrace:            at System.Net.HttpWebRequest.GetResponse()            at SharpMap.Web.Wms.Client.GetRemoteXml(String Url, WebProxy proxy)       InnerException: 

 

thanks for your support.

Coordinator
Dec 1, 2010 at 10:31 AM

please set a breakpoint at SharpMap.Web.Wms.Client.cs Line 249 (may vary), run in debug mode and post the url passed to GetRemoteXml function (strReq).

try the url directly in your web browser as well

Dec 1, 2010 at 10:57 AM

Hi Felix,

In web browser it;s working!

Thanks,

Vivek

 

Coordinator
Dec 1, 2010 at 11:01 AM

and what is the url?

Dec 1, 2010 at 11:09 AM

this URL is working in web browser but when i tried in wms client it's not working 

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map&layer=states&mode=map

the same error Could not download capabilities

Thanks,

Vivek

Coordinator
Dec 1, 2010 at 11:11 AM
FObermaier wrote:

please set a breakpoint at SharpMap.Web.Wms.Client.cs Line 249 (may vary), run in debug mode and post the url passed to GetRemoteXml function (strReq).

try the url directly in your web browser as well

I mean the requested url

Dec 1, 2010 at 11:18 AM

 

                string wmsUrl = "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map&layer=states&mode=map";
                Map wmsmap = new SharpMap.Map(new System.Drawing.Size(700, 700));
                WmsLayer layWms = new WmsLayer("MyMap", wmsUrl);

                layWms.AddLayer("states");
                layWms.SetImageFormat(layWms.OutputFormats[0]);

                layWms.TimeOut = 5000;

                //Map Server Projection ID
                layWms.SRID = 4326;

                wmsmap.Layers.Add(layWms);

and the rested URL is http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map&layer=states&mode=map
as well as I sent I email to you!

Coordinator
Dec 1, 2010 at 11:21 AM

would you please be so kind as to remove the '&layer=states&mode=map' from your wmsUrl variable

Dec 1, 2010 at 11:32 AM

Hi Felix,

I tired this now that line is working 

                string wmsUrl = "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map";
                Map wmsmap = new SharpMap.Map(new System.Drawing.Size(700, 700));
                WmsLayer layWms = new WmsLayer("MyMap", wmsUrl);

                layWms.AddLayer("MyMap");
                layWms.SetImageFormat(layWms.OutputFormats[0]);

WmsLayer layWms = new WmsLayer("MyMap", wmsUrl); and now it's breaking on and it's saying "Cannot add WMS Layer - Unknown layername"

thanks,
Vivek Kumar. 

 

Coordinator
Dec 1, 2010 at 11:38 AM

it should be

layWms.AddLayer("states");

Dec 1, 2010 at 1:00 PM

Hi Felix,

I am getting now this  

 layWms.AddLayer("states"); --->  Cannot add WMS Layer - Unknown layername 

 

                string wmsUrl = "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map";
                Map wmsmap = new SharpMap.Map(new System.Drawing.Size(700, 700));
                WmsLayer layWms = new WmsLayer("MyMap", wmsUrl);

                layWms.AddLayer("states");
                layWms.SetImageFormat(layWms.OutputFormats[0]);

Thanks for the help.

 

Coordinator
Dec 1, 2010 at 1:30 PM

browse to this url

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities

The result should contain all available layers for the map. Adjust the

layWms.AddLayer(...);

line accordingly. Perhaps you need to replace VERSION=1.1.1 with VERSION=1.3.0

Dec 1, 2010 at 4:39 PM

Hi Felix,

thanks for the reply.

now I have code runing with me. 

var map = new SharpMap.Map(new System.Drawing.Size(700, 700));
                //--> Get background           
                //var osmLayer = new TileLayer(new OsmTileSource(), "OSM");
                //map.Layers.Add(osmLayer);
                
                //////Map Server URL 

                string wmsUrl = "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/gmap/htdocs/gmap75.map";
                WmsLayer layWms = new WmsLayer("land_fn", wmsUrl);
                layWms.AddLayer("land_fn");                 
                layWms.SetImageFormat(layWms.OutputFormats[3]);
                //Map Server Transparancy 
                layWms.Transparancy = true;           
                layWms.SetImageFormat("image/png");
                layWms.ContinueOnError = false;
                layWms.BgColor = System.Drawing.Color.Red;
                layWms.Enabled = true;
                //Set timeout to 5 seconds
                layWms.TimeOut = 5000;

                //Map Server Projection ID
                layWms.SRID = 4326;
                map.Layers.Add(layWms);                  
                 map.ZoomToExtents();
but the problem is not getting map. here is below .map which i am taking as a reference IN URL.
MAP

NAME GMAP_DEMO
STATUS ON
SIZE 400 300
SYMBOLSET ../etc/symbols.txt
SHAPEPATH "../data"
IMAGECOLOR 255 0 0
FONTSET ../etc/fonts.txt
UNITS DD
EXTENT -180 -180 180 180
#CONFIG "PROJ_LIB" "../proj/" 
TRANSPARENT on

#
# Start of web interface definition
#
WEB
  
#
# On Windows systems, /tmp and /tmp/ms_tmp/ should be created at the root 
# of the drive where the .MAP file resides.
#
  IMAGEPATH "C:/ms4w/tmp/ms_tmp/" 
  IMAGEURL "/ms_tmp/"

  METADATA 
	"wms_srs"  "EPSG:4326"
  END
END


#
# Start of layer definitions
#


LAYER
 PROJECTION
    "init=epsg:4326"
  END
  NAME land_fn  
  TYPE POLYGON
  STATUS ON
  DATA world_adm0
  CLASS  
    STYLE
      COLOR 240 240 240
      OUTLINECOLOR 199 199 199    
    END
  END
END # layer


END # Map File

Please let me know what I am doing wrong.
Please guide me,
thanks,
Vivek

Coordinator
Dec 1, 2010 at 5:50 PM

Now you are having a different map, did it work for the previous one?

In the map definition you posted, there are two blanks after land_fn, so perhaps you should use

layWms.AddLayer("land_fn  ");

but that is just a vague idea.

Have you tried to get the map using other GIS apps, e.g. QGIS. If not try it with the url defined in wmsUrl.

cheers FObermaier

Dec 1, 2010 at 7:52 PM

Hi FObermaier,

Yes the previous one worked thanks!

Yes I can  see .map file in QGIS, and I can see the map, but when i used to pass this in my wms layer. the map is not coming, not even background color of the wms layer.

Let me know what else I can do?

Thanks for your kind support!

Dec 2, 2010 at 8:18 AM

Hi FObermaier,

what else I can do to make it working.

Coordinator
Dec 2, 2010 at 8:52 AM
Edited Dec 2, 2010 at 9:40 AM

please post the output of

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/gmap75.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities
Dec 2, 2010 at 9:06 AM

Hi FObermaier,

In fact I am geeting nothing the screen is white when I tried to run the file.

and when I used to 

var osmLayer = new TileLayer(new OsmTileSource(), "OSM");              
map.Layers.Add(osmLayer);  

 


 then  OSM map is coming properly with marker and popup.          

but when I used to comment the above layer nothing is coming,

what else I can do now?

thanks for your support.

Coordinator
Dec 2, 2010 at 9:15 AM

I want you to click on the link, then either you get an xml output in your browser or it asks you to save a file.

I either want the xml output or the content of the file

Dec 2, 2010 at 9:22 AM

sorry for the misunderstanding.

the above URL is asking to save mapserv.exe file. when I saved it, and run the file then command prompt opened and nothing happened.

thanks

 

Coordinator
Dec 2, 2010 at 9:24 AM

the output is an xml-file, even if it is called mapserver.exe, that is why it wont run. I want what is in it

Dec 2, 2010 at 9:32 AM

Thanks for the reply.

how I can open .exe file  how I can check what is there inside.

I sent a email to you which is having .exe file.

thanks for your time,

Coordinator
Dec 2, 2010 at 9:42 AM
The link was not what it appered to be.
right click this link and pick save as and rename it to gmap75.xml prior to saving:

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/gmap75.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities
Dec 2, 2010 at 9:54 AM
<!--?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?-->

I sent u email which is having xml file.

thanks,.

Coordinator
Dec 2, 2010 at 10:16 AM

If you browse through the xml file, you'll see that the map you are requesting does not have a layer called "land_fn".

the layers specified are:

<Name>ms4wms</Name>
    <Name>states_01</Name>
    <Name>relief</Name>
    <Name>modis</Name>
    <Name>landsat</Name>
  <Name>cities</Name>
    <Name>cities_poly</Name>
    <Name>cities_label</Name>
    <Name>fedlands</Name>
    <Name>hydro</Name>
    <Name>counties</Name>
  <Name>roads</Name>
    <Name>cty_roads</Name>
    <Name>state_hwy</Name>
    <Name>interstate</Name>
    <Name>roads_anno</Name>
    <Name>roads_anno1</Name>
    <Name>states_02</Name>
    <Name>states_03</Name>

Pick any of those, but remove the <Name> </Name> tags

 

Dec 2, 2010 at 2:18 PM

Hi FObermaier,

I tried with all layers above one by one nothing is working 

 I am getting 

Cannot add WMS Layer - Unknown layername

please let me know what i have to do now.
Coordinator
Dec 2, 2010 at 2:26 PM

please post the wmslayer setup code

Dec 2, 2010 at 3:03 PM

Hi Felix,

I am having this for the wmslayer now.

I am using  below file.

 string wmsUrl = "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/gmap/htdocs/gmap_modified.map";
                WmsLayer layWms = new WmsLayer("world_poly", wmsUrl);
                layWms.AddLayer("world_poly");                 
                layWms.SetImageFormat(layWms.OutputFormats[1]);
                //Map Server Transparancy 
                layWms.Transparancy = false;           
                layWms.SetImageFormat("image/png");
                layWms.ContinueOnError = false;
                layWms.BgColor = System.Drawing.Color.Red;
                layWms.Enabled = true;
                //Set timeout to 5 seconds
                layWms.TimeOut = 5000;

                //Map Server Projection ID
                layWms.SRID = 4326;
                map.Layers.Add(layWms);   
and I checked world_poly is there in the xml file, what you said earlier.  still I am getting blank screen.
Please guide me what else I can do?
thanks for your time and support.
Vivek Kumar.

Coordinator
Dec 2, 2010 at 3:12 PM

right click this link and pick save as and rename it to gmap_modified.xml prior to saving:

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/gmap/htdocs/gmap_modified.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities

and post the content

Dec 2, 2010 at 3:40 PM

Hi FObermaier,

I sent email to you!

thanks,

Vivek 

Dec 2, 2010 at 3:45 PM

Hi ,

I was getting this WARNING: Mandatory mapfile parameter '(at least one of) MAP.PROJECTION, LAYER.PROJECTION or wms_srs metadata' was missing in this context.

so I added below thing in my map file now xml file is coming good.
see the below in bold .
MAP

NAME GMAP_DEMO
STATUS ON
SIZE 400 300
SYMBOLSET ../etc/symbols.txt
SHAPEPATH "../data"
IMAGECOLOR 255 0 0
FONTSET ../etc/fonts.txt
UNITS DD
EXTENT   -180 -90 180 90 # Geographic
CONFIG "PROJ_LIB" "C:/ms4w/apps/gmap/proj/nad/epsg" 
TRANSPARENT off


#
# Start of web interface definition
#
WEB
  
#
# On Windows systems, /tmp and /tmp/ms_tmp/ should be created at the root 
# of the drive where the .MAP file resides.
#
  IMAGEPATH "C:/ms4w/tmp/ms_tmp/" 
  IMAGEURL "/ms_tmp/"

  METADATA 
	"wms_srs"  "EPSG:4326"
  END
END


#
# Start of layer definitions
#


LAYER
PROJECTION
  "proj=latlong"
  "ellps=WGS84"
END
    NAME   "world_poly"
    DATA         'C:/ms4w/apps/gmap/shapefile/world_adm0.shp'
	STATUS       ON
    TYPE         POLYGON
    CLASS
        NAME       'The World'
        STYLE
            OUTLINECOLOR    0 0 0
        END
    END
END # layer


END # Map File
Dec 2, 2010 at 3:47 PM

Hi 

Still I am not getting map file, still it's blank screen.

Please let me know what else I can do?

Thanks,

Vivek Kumar

Coordinator
Dec 2, 2010 at 4:01 PM

The layers I posted above applied only to the gmap75.map example we discussed earlier.

From the xml file you send, as far as I can tell. there should be a valid response. Do you get an error message or just a blank screen?

If you mix this image with some Brutile OSM layer, you will have a mismatch of coordinate systems (OSM: epsg:3875, your wms: epsg:4326)

Have you tried zooming to the wms layers extent? (map.ZoomToBox(layWms.Envelope);)

I cannot help you setting up your mapserver since I have next to no knowledge on how to do that. There are probably lots of other resources.

I'd always try if I can get an image with QGIS and look if there are any differences in the SharpMap setup comapred to that of QGIS and -if so-repair that.

Cheers FObermaier

Dec 2, 2010 at 4:07 PM

Hi FObermaier,

I can understand this. but I am getting only white screen no errors and no warning .

Is still i am missing something.

thanks,

 

Dec 3, 2010 at 7:29 AM

Hi FObermaier,

What else I can do to make it working?

Please guide me I am getting blank screen.

Thanks,

Vivek Kumar.