# Getting data from WMS servers

**URL:** <https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198>\
**Category:** WinForms\
**Created:** [April 29, 2010, 7:51am UTC](https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198 "2010-04-29T07:51:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tda](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/839c29/32.png) [@tda](https://community.thinkgeo.com/u/tda)\
**Post date:** [April 29, 2010, 7:51am UTC](https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198/1 "2010-04-29T07:51:53Z")

</div>

Hi.

I'm&nbsp;currently&nbsp;checking&nbsp;out&nbsp;Map&nbsp;Suite&nbsp;WPF-controls,&nbsp;aiming&nbsp;to&nbsp;show&nbsp;raster&nbsp;data&nbsp;from&nbsp;WMS-servers.

I&nbsp;started&nbsp;out&nbsp;with&nbsp;the&nbsp;"LoadAWmsImage"&nbsp;from&nbsp;the&nbsp;HowDoISamples,&nbsp;wich&nbsp;seems&nbsp;to&nbsp;work&nbsp;fine.

I'm&nbsp;having&nbsp;some&nbsp;problems&nbsp;though,&nbsp;using&nbsp;other&nbsp;WMS&nbsp;services&nbsp;than&nbsp;the&nbsp;one&nbsp;in&nbsp;the&nbsp;sample&nbsp;(wmssamples.thinkgeo.com/WmsServer.aspx)

At&nbsp;the&nbsp;moment&nbsp;I'm&nbsp;using&nbsp;this&nbsp;free&nbsp;WMS&nbsp;for&nbsp;testing:&nbsp;wms.jpl.nasa.gov/wms.cgi?,&nbsp;but&nbsp;I've&nbsp;encountered&nbsp;similar&nbsp;problems&nbsp;on&nbsp;many&nbsp;other&nbsp;WMS's.

Here&nbsp;is&nbsp;some&nbsp;sample&nbsp;code:

`        private void ShowEarthMap()        {            string url = "onearth.jpl.nasa.gov/wms.cgi";            MyMap.MapUnit = GeographyUnit.DecimalDegree;            WmsRasterLayer wmsImageLayer = new WmsRasterLayer(new Uri(url));            wmsImageLayer.UpperThreshold = double.MaxValue;            wmsImageLayer.LowerThreshold = 0;            wmsImageLayer.Open();            RectangleShape bb = wmsImageLayer.GetBoundingBox();            MyMap.CurrentExtent = bb;            wmsImageLayer.ActiveLayerNames.Add("modis");            wmsImageLayer.Crs = "EPSG:4326";            wmsImageLayer.OutputFormat = "IMAGE/PNG";            LayerOverlay staticOverlay = new LayerOverlay();            staticOverlay.Layers.Add("wmsImageLayer", wmsImageLayer);            MyMap.Overlays.Add(staticOverlay);            // GetRequestUrl for debug            string requestUrl = wmsImageLayer.GetRequestUrl(MyMap.CurrentExtent, (int)MyMap.Width, (int)MyMap.Height);            Debug.WriteLine(requestUrl);            wmsImageLayer.Close();            this.Status.Text = requestUrl;            MyMap.Refresh();        }`

**Problem&nbsp;1:&nbsp;Invalid&nbsp;Bounding&nbsp;Box.**

Running&nbsp;the&nbsp;above&nbsp;code,&nbsp;the&nbsp;server&nbsp;responds&nbsp;with&nbsp;"Bounding&nbsp;box&nbsp;has&nbsp;an&nbsp;invalid&nbsp;area".

Examining&nbsp;the&nbsp;requesturl&nbsp;I&nbsp;see&nbsp;that&nbsp;it&nbsp;contains&nbsp;BBOX=-260.15625,-185.625,260.15625,185.625&nbsp;while&nbsp;wimsImageLayer.GetBoundingBox()&nbsp;returns&nbsp;-180,90,180,-90.

**Question&nbsp;1** :What&nbsp;can&nbsp;I&nbsp;do&nbsp;to&nbsp;avoid&nbsp;generating&nbsp;a&nbsp;request&nbsp;for&nbsp;non-existing&nbsp;bounding&nbsp;box?

&nbsp;

**Problem&nbsp;2:&nbsp;Invalid&nbsp;format**

A&nbsp;quick&nbsp;hack&nbsp;to&nbsp;solve&nbsp;P1&nbsp;is&nbsp;to&nbsp;divide&nbsp;all&nbsp;coordinates&nbsp;of&nbsp;the&nbsp;bbox&nbsp;with&nbsp;2,&nbsp;and&nbsp;then&nbsp;forcing&nbsp;a&nbsp;valid&nbsp;area&nbsp;in&nbsp;the&nbsp;requesturl.

Now,&nbsp;the&nbsp;server&nbsp;complains&nbsp;that:&nbsp;"The&nbsp;format&nbsp;"IMAGE/PNG"&nbsp;is&nbsp;invalid".

Fiddling&nbsp;with&nbsp;the&nbsp;requesturl&nbsp;in&nbsp;a&nbsp;browser,&nbsp;I&nbsp;can&nbsp;get&nbsp;a&nbsp;map&nbsp;shown&nbsp;if&nbsp;the&nbsp;format&nbsp;is&nbsp;changed&nbsp;to&nbsp;"image/png"&nbsp;(just&nbsp;lowercasing&nbsp;the&nbsp;format),&nbsp;but&nbsp;doing&nbsp;the&nbsp;same&nbsp;trick&nbsp;in&nbsp;my&nbsp;sample,&nbsp;I&nbsp;now&nbsp;get&nbsp;an&nbsp;exception&nbsp;from&nbsp;GetRequestUrl(..):&nbsp;&nbsp;"This&nbsp;image&nbsp;format&nbsp;is&nbsp;not&nbsp;supported&nbsp;in&nbsp;the&nbsp;Wms&nbsp;server".

This,&nbsp;_I&nbsp;think_,&nbsp;is&nbsp;because&nbsp;the&nbsp;WmsRasterLayer&nbsp;does&nbsp;some&nbsp;validation&nbsp;of&nbsp;the&nbsp;parameters&nbsp;before&nbsp;the&nbsp;requesturl&nbsp;is&nbsp;generated.&nbsp;When&nbsp;examining&nbsp;the&nbsp;output&nbsp;of&nbsp;WmsRasterLayer.GetServerOutputFormats(),&nbsp;I&nbsp;see&nbsp;that&nbsp;this&nbsp;list&nbsp;contains&nbsp;the&nbsp;upper-case&nbsp;format,&nbsp;but&nbsp;not&nbsp;the&nbsp;lowercase&nbsp;format.

**Question&nbsp;2** :&nbsp;Can&nbsp;I&nbsp;force&nbsp;case-insensitive&nbsp;validation&nbsp;or&nbsp;something&nbsp;else&nbsp;to&nbsp;get&nbsp;resolve&nbsp;this&nbsp;issue?

&nbsp;

**Problem&nbsp;3:&nbsp;Invalid&nbsp;Crs**

Failing&nbsp;to&nbsp;use&nbsp;the&nbsp;WMS&nbsp;from&nbsp;P1&nbsp;and&nbsp;P2,&nbsp;I&nbsp;now&nbsp;tried&nbsp;another:

`string url = "129.206.229.147/ors-tilecache/tilecache.py?";`

`wmsImageLayer.ActiveLayerNames.Add("ors-osm");`

`wmsImageLayer.OutputFormat = "IMAGE/PNG";`

This&nbsp;gives&nbsp;me&nbsp;an&nbsp;exception&nbsp;when&nbsp;calling&nbsp;GetRequestUrl:&nbsp;"This&nbsp;CRS&nbsp;is&nbsp;not&nbsp;supported&nbsp;in&nbsp;the&nbsp;Wms&nbsp;server:"

Digging&nbsp;in&nbsp;to&nbsp;this&nbsp;problem&nbsp;I&nbsp;found&nbsp;out&nbsp;that&nbsp;wmsImageLayer.GetServerCrss&nbsp;returns&nbsp;an&nbsp;empty&nbsp;collection,&nbsp;so&nbsp;I&nbsp;guess&nbsp;that&nbsp;this&nbsp;is&nbsp;similar&nbsp;to&nbsp;P2:&nbsp;GetRequestUrl&nbsp;does&nbsp;some&nbsp;validation&nbsp;to&nbsp;the&nbsp;parameters,&nbsp;wich&nbsp;fails.

**Question&nbsp;3** :&nbsp;Is&nbsp;there&nbsp;any&nbsp;way&nbsp;to&nbsp;bypass&nbsp;this&nbsp;validation.&nbsp;The&nbsp;WMS&nbsp;in&nbsp;question&nbsp;has&nbsp;several&nbsp;valid&nbsp;Crss?

&nbsp;

I've&nbsp;tried&nbsp;with&nbsp;a&nbsp;few&nbsp;other&nbsp;available&nbsp;services&nbsp;but&nbsp;nevertheless&nbsp;I&nbsp;have&nbsp;not&nbsp;succeeded&nbsp;in&nbsp;displaying&nbsp;maps&nbsp;from&nbsp;other&nbsp;servers&nbsp;than&nbsp;the&nbsp;one&nbsp;available&nbsp;at:&nbsp;wmssamples.thinkgeo.com/WmsServer.aspx

Do&nbsp;you&nbsp;know&nbsp;of&nbsp;any&nbsp;other&nbsp;WMS&nbsp;services&nbsp;that&nbsp;works&nbsp;with&nbsp;WmsRasterLayer?

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [May 4, 2010, 2:28am UTC](https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198/2 "2010-05-04T02:28:59Z")

</div>

Thomas,

Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;questions,&nbsp;hope&nbsp;my&nbsp;following&nbsp;answer&nbsp;can&nbsp;give&nbsp;you&nbsp;some&nbsp;hints.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
1)&nbsp;About&nbsp;the&nbsp;bounding&nbsp;box&nbsp;sent&nbsp;to&nbsp;the&nbsp;server&nbsp;side.  
When&nbsp;we&nbsp;set&nbsp;the&nbsp;CurrentExtent&nbsp;to&nbsp;the&nbsp;map&nbsp;control,&nbsp;we&nbsp;will&nbsp;do&nbsp;some&nbsp;judgment&nbsp;according&nbsp;to&nbsp;the&nbsp;Map&nbsp;Width&nbsp;and&nbsp;Height.&nbsp;The&nbsp;APIs&nbsp;can&nbsp;be&nbsp;found&nbsp;easily&nbsp;in&nbsp;the&nbsp;helper&nbsp;class&nbsp;ExtentHelper.&nbsp;For&nbsp;example:  
ExtentHelper.GetDrawingExtent(extent,&nbsp;mapWidth,&nbsp;mapHeight);  
&nbsp;  
2)&nbsp;About&nbsp;the&nbsp;Problem&nbsp;2&nbsp;and&nbsp;Problem&nbsp;3,&nbsp;I&nbsp;think&nbsp;they&nbsp;belong&nbsp;to&nbsp;the&nbsp;same&nbsp;problem.&nbsp;As&nbsp;you&nbsp;know,&nbsp;the&nbsp;OGC&nbsp;set&nbsp;up&nbsp;a&nbsp;standards&nbsp;for&nbsp;the&nbsp;WMS.&nbsp;And&nbsp;we&nbsp;coding&nbsp;against&nbsp;very&nbsp;strictly&nbsp;according&nbsp;to&nbsp;the&nbsp;standards,&nbsp;and&nbsp;we&nbsp;set&nbsp;up&nbsp;a&nbsp;standard&nbsp;server&nbsp;which&nbsp;apply&nbsp;the&nbsp;standards&nbsp;very&nbsp;strictly.  
&nbsp;  
Interesting&nbsp;enough&nbsp;though,&nbsp;I&nbsp;did&nbsp;some&nbsp;investigations&nbsp;on&nbsp;the&nbsp;open&nbsp;wms&nbsp;server&nbsp;provided&nbsp;by&nbsp;the&nbsp;OGC,&nbsp;and&nbsp;found&nbsp;that&nbsp;we&nbsp;also&nbsp;failed&nbsp;to&nbsp;support&nbsp;it.&nbsp;Following&nbsp;is&nbsp;the&nbsp;code:  
  
&nbsp;  
`WmsRasterLayer wmsImageLayer = new WmsRasterLayer(new Uri("labs.metacarta.com/wms/vmap0?"));wmsImageLayer.UpperThreshold = double.MaxValue;wmsImageLayer.LowerThreshold = 0;wmsImageLayer.ActiveLayerNames.Add("basic");wmsImageLayer.Open();            Debug.WriteLine(wmsImageLayer.GetRequestUrl(winformsMap1.CurrentExtent, winformsMap1.Width, winformsMap1.Height));`  
  
Then&nbsp;I&nbsp;dig&nbsp;out&nbsp;the&nbsp;reason&nbsp;is&nbsp;that&nbsp;its&nbsp;OnlineResource&nbsp;set&nbsp;did&nbsp;not&nbsp;match&nbsp;its&nbsp;url&nbsp;which&nbsp;make&nbsp;the&nbsp;final&nbsp;string&nbsp;sent&nbsp;to&nbsp;the&nbsp;server&nbsp;is&nbsp;wrong.&nbsp;See&nbsp;following&nbsp;snap&nbsp;shot.&nbsp;&nbsp;So&nbsp;it&nbsp;seems&nbsp;so&nbsp;strict&nbsp;WMS&nbsp;server&nbsp;is&nbsp;very&nbsp;rare.  
&nbsp;  
&nbsp;

 ![](https://community.thinkgeo.com/uploads/default/original/2X/2/2b619de49f74c4e6eb9014d19f1a49e4db257e44.png)  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale  
&nbsp;

---

<div class="post-metadata">

**Author:** ![tda](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/839c29/32.png) [@tda](https://community.thinkgeo.com/u/tda)\
**Post date:** [May 10, 2010, 11:46am UTC](https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198/3 "2010-05-10T11:46:15Z")

</div>

Q1:&nbsp;  
&nbsp;OK,&nbsp;I’ve&nbsp;succeeded&nbsp;to&nbsp;calculate&nbsp;a&nbsp;usable&nbsp;scale&nbsp;ratio&nbsp;on&nbsp;the&nbsp;rectangle&nbsp;returned&nbsp;by&nbsp;GetDrawingExtent(…)&nbsp;and&nbsp;display&nbsp;some&nbsp;maps&nbsp;from&nbsp;the&nbsp;ThinkGeo&nbsp;WMS.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Q2+Q3:&nbsp;  
&nbsp;Hmm.&nbsp;I’m&nbsp;then&nbsp;about&nbsp;to&nbsp;conclude&nbsp;that&nbsp;since&nbsp;there&nbsp;obviously&nbsp;are&nbsp;only&nbsp;very&nbsp;few&nbsp;standards-compliant&nbsp;Web&nbsp;Map&nbsp;Services,&nbsp;the&nbsp;Map&nbsp;Suite&nbsp;controls&nbsp;have&nbsp;very&nbsp;limited&nbsp;use&nbsp;if&nbsp;the&nbsp;only&nbsp;access&nbsp;you&nbsp;have&nbsp;to&nbsp;map-data&nbsp;is&nbsp;through&nbsp;a&nbsp;WMS.&nbsp;  
&nbsp;That&nbsp;is&nbsp;a&nbsp;pity.&nbsp;  
&nbsp;Do&nbsp;you&nbsp;have&nbsp;any&nbsp;plans&nbsp;to&nbsp;change&nbsp;the&nbsp;implementation&nbsp;of&nbsp;WmsRasterLayer,&nbsp;so&nbsp;that&nbsp;it&nbsp;can&nbsp;be&nbsp;used&nbsp;in&nbsp;environments&nbsp;where&nbsp;a&nbsp;standards-compliant&nbsp;WMS&nbsp;is&nbsp;not&nbsp;available?&nbsp;  
&nbsp;One&nbsp;way&nbsp;could&nbsp;be&nbsp;to&nbsp;not&nbsp;trust&nbsp;the&nbsp;output&nbsp;of&nbsp;GetCapabilities&nbsp;and&nbsp;let&nbsp;the&nbsp;user&nbsp;configure&nbsp;the&nbsp;options.&nbsp;  
&nbsp;&nbsp;  
&nbsp;/Thomas

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [May 10, 2010, 9:55pm UTC](https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198/4 "2010-05-10T21:55:57Z")

</div>

Thomas,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;input&nbsp;and&nbsp;suggestions.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Personally&nbsp;I&nbsp;agree&nbsp;with&nbsp;your&nbsp;suggestions,&nbsp;it&nbsp;seems&nbsp;too&nbsp;rigid&nbsp;to&nbsp;get&nbsp;all&nbsp;the&nbsp;information&nbsp;from&nbsp;the&nbsp;capabilities.&nbsp;We&nbsp;will&nbsp;consider&nbsp;this&nbsp;carefully&nbsp;and&nbsp;see&nbsp;if&nbsp;we&nbsp;can&nbsp;handle&nbsp;this&nbsp;in&nbsp;future.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale&nbsp;

---

<div class="post-metadata">

**Author:** ![tda](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/839c29/32.png) [@tda](https://community.thinkgeo.com/u/tda)\
**Post date:** [May 11, 2010, 9:38am UTC](https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198/5 "2010-05-11T09:38:28Z")

</div>

I&nbsp;had&nbsp;hoped&nbsp;that&nbsp;the&nbsp;WmsRasterLayer&nbsp;was&nbsp;more&nbsp;mature&nbsp;than&nbsp;it&nbsp;currently&nbsp;is.&nbsp;I’ll&nbsp;take&nbsp;a&nbsp;look&nbsp;at&nbsp;it&nbsp;again&nbsp;later&nbsp;to&nbsp;see&nbsp;if&nbsp;things&nbsp;have&nbsp;changed,&nbsp;but&nbsp;for&nbsp;now&nbsp;it&nbsp;is&nbsp;unusable&nbsp;for&nbsp;our&nbsp;needs.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thank&nbsp;you&nbsp;for&nbsp;your&nbsp;time.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thomas

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [May 11, 2010, 10:28pm UTC](https://community.thinkgeo.com/t/getting-data-from-wms-servers/1198/6 "2010-05-11T22:28:28Z")

</div>

Thomas,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;input&nbsp;and&nbsp;suggestions.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;think&nbsp;currently&nbsp;it&nbsp;seems&nbsp;the&nbsp;WmsRasterLayers&nbsp;can&nbsp;only&nbsp;be&nbsp;utilized&nbsp;when&nbsp;the&nbsp;WMS&nbsp;server&nbsp;is&nbsp;implemented&nbsp;in&nbsp;very&nbsp;strict&nbsp;standards,&nbsp;like&nbsp;our&nbsp;WorldMapKit&nbsp;Wms&nbsp;server.&nbsp;Hope&nbsp;we&nbsp;can&nbsp;get&nbsp;it&nbsp;enhanced&nbsp;in&nbsp;future.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale&nbsp;
