WMS vs. WMTS

When it comes to building quality GIS applications, a great base map is essential. Services like ThinkGeo Cloud make extensive use of newer Vector tile technology. And ThinkGeo WebApi projects are built on XYZ tile technology. But, the older WMS and WMTS services are still a mainstay of GIS basemaps and there is frequent confusion around these specifications and which is better suited for different scenarios. We’ll try try clarify some of the confusion in this article.

WMS and WMTS Defined

WMS (Web Map Service) is a standard protocol developed by the Open Geospatial Consortium in 1999 for serving georeferenced map images over the Internet. WMS allows a client to request an arbitrary geographic region and scale. The map is generated real-time when the client makes the request and there are no pre-defined and cached tiles. WMS also allows for the client to request the map to be styled dynamically by providing a SLD (Styled Layer Descriptor) in the request.

Typically WMS is a good option when your map:

  • needs to be generated real-time with a frequently changing data source.

  • needs to have different projections, variable styling and layers, and support arbitrary scales.

  • has a simple dataset and typically renders quickly.

WMTS (Web Map Tiled Service) is a standard protocol for serving pre-rendered or run-time computed georeferenced map tiles over the Internet. The specification was developed and first published by the Open Geospatial Consortium in 2010. A WMTS service delivers tiles - usually 256 x 256 pixels. The main advantage of WMTS is that they can be pre-generated and cached on both the client and server. This leads to much better performance and reduced bandwidth usage.

WMTS is a better option when your map:

  • needs to perform quickly and/or support caching.

  • For larger coverage areas or rendering intensive maps where the data and styling are not dynamic.

  • When you want to combine tiles from multiple WMTS services into one basemap.

ThinkGeo and WMS/WMTS

All ThinkGeo components support consumption of both WMS and WMTS services. You can find examples using both types of services in our Desktop WPF ‘HowDoI’ samples here, but these layers work the same in our Web and Mobile components also.

Sample Code

Let’s walk through a few lines of code that show just how simple consuming these types of services can be using the WMSRasterLayer and WMTSLayer.

Step 1 - all maps need the MapUnit set. In this example, we’ll use meter.

  
    // It is important to set the map unit first to either feet, meters or decimal degrees.
    mapView.MapUnit = GeographyUnit.Meter;
  

Step 2 - To consume a WMS service, use the WMSRasterLayer shown below.

  
    // Create the WMS layer using the parameters below.
    // This is a public service and is very slow most of the time.
    WmsRasterLayer wmsImageLayer = new WmsRasterLayer(new Uri("http://ows.mundialis.de/services/service"));
    wmsImageLayer.UpperThreshold = double.MaxValue;
    wmsImageLayer.LowerThreshold = 0;
    wmsImageLayer.ActiveLayerNames.Add("OSM-WMS");
    wmsImageLayer.ActiveStyleNames.Add("default");            
    wmsImageLayer.Exceptions = "application/vnd.ogc.se_xml";
  

Step 3 - To consume a WMTS service, use the WMTSLayer shown below. Note the extra lines of code to set the TileMatrixSetName and TileCache - both of which are not available in WMS.

  
    // Create a WMTS overlay using the parameters below.
    // This is a public service and performance may be slow.
    WmtsLayer wmtsLayer = new WmtsLayer
    {
        DrawingExceptionMode = DrawingExceptionMode.DrawException,
        WmtsSeverEncodingType = WmtsSeverEncodingType.Restful
    };
    wmtsLayer.ServerUris.Add(new Uri("https://wmts.geo.admin.ch/1.0.0"));
    wmtsLayer.CapabilitesCacheTimeout = new TimeSpan(0, 0, 0, 1);
    wmtsLayer.ActiveLayerName = "ch.swisstopo.pixelkarte-farbe-pk25.noscale";
    wmtsLayer.ActiveStyleName = "default";
    wmtsLayer.OutputFormat = "image/png";
    wmtsLayer.TileMatrixSetName = "21781_26";
    wmtsLayer.TileCache = new FileRasterTileCache(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "WmtsTmpTileCache"));
  

Step 4 - Add the WMS or WMTS layer to an overlay and add the overlay to the map. Set the current extent and refresh.

  
    //Add the new WMS or WMTS Layer to our LayerOverlay
    LayerOverlay layerOverlay = new LayerOverlay();
    //add the WMS layer to the map
    layerOverlay.Layers.Add(wmsImageLayer);
    //or add the WMTS layer
    layerOverlay.Layers.Add(wmtsLayer);

    //Add the overlay to the mapView's Overlay collection.
    mapView.Overlays.Add(layerOverlay);

    // Set the current extent to the Eiger - a famous peak in Switzerland.
    mapView.CurrentExtent = new RectangleShape(641202.9893498598, 159695.95554381475, 645651.6243713424, 156646.11813217978);

    // Refresh the map.
    await mapView.RefreshAsync();
  

If you have any questions on using our WMS or WMTS layers, please contact sales@thinkgeo.com and we will be happy to help. Sign up for a free evaluation to view our samples and start building today!

Previous
Previous

Leaflet vs. OpenLayers - Round 2

Next
Next

ThinkGeo Cloud Javascript API