Using the WebRequest class to query a map image from the WMS servlet

Query schemas for the xServer internet WMS adapter

The PTV WMS adapter provides a WMS (Web Map Service) interface for requesting maps rendered by PTV xMap Server. Currently the PTV WMS adapter supports version 1.1.1 and version 1.3 of OGC's (Open Geospatial Consortium) WMS specification. For detailed information about WMS, please visit OGS's web site at http://www.opengeospatial.org/.

The layers made available by the PTV WMS adapter can be queried using a capabilities request. 

https://xmap-eu-n-test.cloud.ptvgroup.com/WMS/WMS?REQUEST=GetCapabilities&VERSION=1.3.0&service=WMS&format=text/xml&xtok=your_token

A request to query a WMS image usually looks like:

https://xmap-eu-n.cloud.ptvgroup.com/WMS/WMS?REQUEST=GetMap&width=256&height=256&bbox=6.01554,49.50647,6.36157,49.73065&format=image/png&version=1.1.1&layers=xmap-ajaxbg&srs=EPSG:4326&styles= 

Note: Requests using the layer “xmap-ajaxbg” are not billed. You do not need to specify a token for requests when using this profile. All other layers need an additional xtok parameter.

Query tiled maps

There is also a request schema which is optimized to query background layers in a shorter and more cache-friendly manner. These images are usually used by interactive map controls. The request schema is GetTile/{layer}/{x}/{y}{z}. For example:

http://xmap-eu-n-test.cloud.ptvgroup.com/WMS/GetTile/xmap-ajaxbg/2117/1391/12.png

The throughput can be increased by using the domain ajaxbg1-{cluster} instad of xmap-{cluster} as domain. This will bypass restrictions for parallel downloads per domain. An example request:

http://ajaxbg1-eu-n-test.cloud.ptvgroup.com/WMS/GetTile/xmap-ajaxbg/2117/1391/12.png

Load a map image in C#

To load a WMS image in C#, you can use the WebRequest class and initialize a System.Drawing.Image object from the response string.

public static void TestWebRequest()
{
    var request = WebRequest.Create(
        "https://xmap-eu-n.cloud.ptvgroup.com/WMS/WMS?REQUEST=GetMap&width=600&height=600&bbox=661904,6350636,700381,6389113"+
        "&format=image/png&version=1.1.1&layers=xmap-plain&srs=EPSG:505456&styles=&xtok=<your token>");
    var response = request.GetResponse();
    var bitmap = System.Drawing.Image.FromStream(response.GetResponseStream());
    response.Close();
}