ThinkGeo.com    |     Documentation    |     Premium Support

WmtsAsyncLayer - MatrixSet is 0

Hello,
I modified the WMTS-Part of your “HowTo Sample” to use a very common WMTS-Service in germany.
A get the exception “There are 0 matrix sets in this WMTS Server” with the following code.

var layerOverlay = new WmtsOverlay(new Uri("https://sgx.geodatenzentrum.de/wmts_basemapde"));
layerOverlay.ActiveLayerName = "de_basemapde_web_raster_farbe";
layerOverlay.ActiveStyleName = "default";
layerOverlay.TileMatrixSetName = "DE_EPSG_25832_ADV";
layerOverlay.OutputFormat = "image/png";
layerOverlay.TileCache = new FileRasterTileCache("C:\\temp\\layerOverlay");
MapView.Overlays.Add(layerOverlay);

Any suggestion?
Regards Torsten

Hi Torsten,

The following code works for me with V14.3.1. I put some comments in the code regarding my changes.

  private async void mapView_Loaded(object sender, RoutedEventArgs e)
  {
      var layerOverlay = new WmtsOverlay(new Uri("https://sgx.geodatenzentrum.de/wmts_basemapde"));
      layerOverlay.ActiveLayerName = "de_basemapde_web_raster_farbe";
      layerOverlay.ActiveStyleName = "default";
      layerOverlay.TileMatrixSetName = "DE_EPSG_25832_ADV";
      layerOverlay.OutputFormat = "image/png";
      // provide a tileId to the cache otherwise a new cache folder will be created every time. 
      layerOverlay.TileCache = new FileRasterTileCache("C:\\temp\\layerOverlay", "tileId");
      mapView.Overlays.Add(layerOverlay);

      mapView.MapUnit = GeographyUnit.Meter;
      await layerOverlay.OpenAsync();

      // The following 2 lines fetch the scales from the server, and apply those scales to the MapView
      // Otherwise, the map will use the default scale collection (with 20 zooms) 
      var scales = layerOverlay.TileMatrixSet.Matrices.Select(m => m.Scale);
      mapView.ZoomScales = new Collection<double>(scales.ToList());

      // Set the initial extent and scale
      mapView.CenterPoint = layerOverlay.GetBoundingBox().GetCenterPoint();
      mapView.CurrentScale = mapView.ZoomScales[1];

      await mapView.RefreshAsync();
  }

Thanks,
Ben

Hello Ben,
thanks, it works for me - i forgot to set a proxy…
Regards Torsten

Hallo Ben,

when I try to use an another WMTS Layer with your code, an error occurs:

System.ApplicationException: “There are 0 matrix sets in this WMTS Server, but EU_EPSG_25832_TOPPLUS is not one of them. Please check WebBasedLayer.TileMatrixSetName property”

private async void WmtsTopPlusOpen_Click(object sender, RoutedEventArgs e)
{
var layerOverlay = new WmtsOverlay(new Uri(“https://sgx.geodatenzentrum.de/wmts_topplus_open”));
layerOverlay.ActiveLayerName = “web”;
layerOverlay.ActiveStyleName = “default”;
layerOverlay.TileMatrixSetName = “EU_EPSG_25832_TOPPLUS”;
layerOverlay.OutputFormat = “image/png”;
// provide a tileId to the cache otherwise a new cache folder will be created every time.
layerOverlay.TileCache = new FileRasterTileCache(“C:\_temp\layerOverlay2”, “tileId”);
mapView.Overlays.Add(layerOverlay);

mapView.MapUnit = GeographyUnit.Meter;
await layerOverlay.OpenAsync();

// The following 2 lines fetch the scales from the server, and apply those scales to the MapView
// Otherwise, the map will use the default scale collection (with 20 zooms) 
var scales = layerOverlay.TileMatrixSet.Matrices.Select(m => m.Scale);
mapView.ZoomScales = new Collection<double>(scales.ToList());

// Set the initial extent and scale
mapView.CenterPoint = layerOverlay.GetBoundingBox().GetCenterPoint();
mapView.CurrentScale = mapView.ZoomScales[1];

await mapView.RefreshAsync();

}

What’s my mistake?
Regards Torsten

Hi Torsten,

Can you connect to https://sgx.geodatenzentrum.de/wmts_topplus_open in QGis, any chance the URI is incorrect? can you have a try on your side?

Thanks,
Ben

Hello Ben,
thanks for your quick response. Yes, i can connect TopPlusOpen. The url i use in the connection dialog in QGis is ‘https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml’.

Regards Torsten

Hi Torsten,

I changed the code as following and it works. Some notes:

  1. put “/1.0.0” as part of the request uri
  2. Use the extent of the Matrix instead of the BBox. It seems the server set the entire world as its bounding box while it only has the data for europe.
  3. There are some wmts improvements in the recent beta, pull the latest version if you see any issues.
{
  var layerOverlay = new WmtsOverlay(new Uri("https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0"));
  layerOverlay.ActiveLayerName = "web";
  layerOverlay.ActiveStyleName = "default";
  layerOverlay.TileMatrixSetName = "EU_EPSG_25832_TOPPLUS";
  layerOverlay.OutputFormat = "image / png";
  layerOverlay.TileCache = new FileRasterTileCache(@"C:\_temp\layerOverlay2", "tileId");
  MapView.Overlays.Add(layerOverlay);

  MapView.MapUnit = GeographyUnit.Meter;
  await layerOverlay.OpenAsync();

  // The following 2 lines fetch the scales from the server, and apply those scales to the MapView
  // Otherwise, the map will use the default scale collection (with 20 zooms) 
   //var scales = layerOverlay.TileMatrixSet.Matrices.Select(m => m.Scale);
   var scales = layerOverlay.TileMatrixSet.GetScales();
   MapView.ZoomScales = new Collection<double>(scales.ToList());

  // Set the initial extent and scale
  //MapView.CenterPoint = layerOverlay.GetBoundingBox().GetCenterPoint();
  //MapView.CurrentScale = MapView.ZoomScales[1];

  var bbox = layerOverlay.TileMatrixSet.TileMatrices[1].BoundingBox;
  MapView.CenterPoint = bbox.GetCenterPoint();
  MapView.CurrentScale = MapView.ZoomScales[1];


  await MapView.RefreshAsync();
}

Thanks,
Ben

Hallo Ben,
Thanks, it works for me.
Regards Torsten

That’s awesome! :+1: