ThinkGeo.com    |     Documentation    |     Premium Support

WMTS layer error

Hello,

I can’t get a WMTS layer to show in my map (I’m using 13.0.0-beta426)
I’ve been trying for a long time now, but I keep getting messages ‘Value can’t be null’, parametername: bitmap.

Can you help me?

My code sofar:
Dim wmtsOverlay = New WmtsTiledOverlay(New Uri() {New Uri(“https://tiles1.geoserve.eu/Mosaics/tileserver/20220831_20220716_SV_RD_8bit_RGBMosaic_50cm_Nederland/wmts”)},
WmtsSeverEncodingType.Kvp)
wmtsOverlay.DrawingExceptionMode = DrawingExceptionMode.DrawException
wmtsOverlay.Open()
wmtsOverlay.ActiveLayerName = “20220831_20220716_SV_RD_8bit_RGBMosaic_50cm_Nederland”
wmtsOverlay.ActiveStyleName = “default”
wmtsOverlay.TileMatrixSetName = “GoogleMapsCompatible”
wmtsOverlay.OutputFormat = “image/jpgpng”
wmtsOverlay.TileCache = New FileRasterTileCache(“C:\temp\wmtsOverlay”)
mapView.Overlays.Add(wmtsOverlay)
mapView.Refresh(OverlayRefreshType.Redraw)

Kind regards,
Guido van den Boom

Hey @G_Vandenboom,

I think there might be something wrong with that WMTS configuration. I managed to get to their Capabilities.xml, which allowed me to see where their tiles are supposed to be queried, but just trying to get a top level tile resulted in an error:

I also tried loading up the WMTS in QGIS to make sure I wasn’t going crazy, but it also had issues displaying the WMTS:

From what I can tell, it looks like they updated something recently. Their configuration is a bit of a mix between the GetCapabilities in KVP encoding, but their GetTiles is supposedly setup for RESTful encoding but errors out. Maybe they are still in the process of upgrading their system?

Thanks,
Kyle

Hey @Kyle_Day,

My colleague is able to open the WMTS in QGis. Please find attached the Qgis file.
I hope this can help to solve the issue.

Kind regards,
Guido van den Boom

TestWMTS.zip (5.2 KB)

Hey @G_Vandenboom,

Yes, I am able to see the WMTS now. I was able to get it working on my side in a sample application. I had to intercept the SendingWebRequest event and flip the TileRow and TileCol values because they are expecting Z/Y/X instead of the usual Z/X/Y pattern. I also had to make sure to the set the TileSizeMode to Small to ensure it processes 256x256 tiles. Here’s the code:

private void MapView_Loaded(object sender, RoutedEventArgs e)
{
    // Set the map's unit of measurement to meters(Spherical Mercator)
    mapView.MapUnit = GeographyUnit.Meter;
    WmtsTiledOverlay wmtsOverlay = new WmtsTiledOverlay(new []{new Uri(@"https://tiles1.geoserve.eu/Mosaics/tileserver/20220831_20220716_SV_RD_8bit_RGBMosaic_50cm_Nederland/wmts")},WmtsSeverEncodingType.Kvp);
    wmtsOverlay.TileSizeMode = TileSizeMode.Small;
    wmtsOverlay.ActiveLayerName = "20220831_20220716_SV_RD_8bit_RGBMosaic_50cm_Nederland";
    wmtsOverlay.ActiveStyleName = "default";
    wmtsOverlay.TileMatrixSetName = "GoogleMapsCompatible";
    wmtsOverlay.OutputFormat = "image/jpg";
    wmtsOverlay.TileCache = new FileRasterTileCache(@"C:\temp\wmtsOverlay");
    wmtsOverlay.SendingWebRequest += WmtsOverlayOnSendingWebRequest;
    mapView.Overlays.Add(wmtsOverlay);
    // Set the map extent
    wmtsOverlay.Open();
    mapView.CurrentExtent = wmtsOverlay.GetBoundingBox();
}
private void WmtsOverlayOnSendingWebRequest(object sender, SendingWebRequestEventArgs e)
{
    string originalQueryString = e.WebRequest.RequestUri.Query;
    if (originalQueryString.Contains("GetTile"))
    {
        // Flip the TileRow and TileCol values
        var arguments = originalQueryString
            .Substring(1) // Remove '?'
            .Split('&')
            .Select(q => q.Split('='))
            .ToDictionary(q => q.FirstOrDefault(), q => q.Skip(1).FirstOrDefault());
        var row = arguments["TileRow"];
        var column = arguments["TileCol"];
        var uri = e.WebRequest.RequestUri.AbsoluteUri.Replace($"TileRow={row}", $"TileRow={column}").Replace($"TileCol={column}", $"TileCol={row}");
        e.WebRequest = WebRequest.Create(uri);
    }
}

Thanks,
Kyle

Hey @Kyle_Day,

Thank you very much, it works !!!

Just one more question:
The tiles outside the images show ‘value can’t be null’. Can this be solved in the overlay (qgis doesn’t have this problem)?

Kind regards,
Guido van den Boom

Hey @G_Vandenboom,

Yeah, you can remove those drawing exception by setting the following on the wmts overlay:

wmtsOverlay.DrawingExceptionMode = DrawingExceptionMode.ThrowException;

Just set this back to the default if you run into any other issues with the WMTS layer.

Thanks,
Kyle