2

I am trying to add this WMTS as a background layer in QWC2.

https://geoegl.msp.gouv.qc.ca/carto/wmts?SERVICE=WMTS&REQUEST=GetCapabilities&VERSION=1.3.0

In the GetCapabilities results I see 22 scale denominators that I am trying to convert into resolution values for my themesConfig.json file in QWC2.

I have been searching on internet for days now but I can't find any info or formula on how to do this.

Does such a formula actually exist ? Or is there a way I haven't seen to make QWC2 figure out the resolutions itself ?

2 Answers 2

4

Ian's answer was quite helpful (thanks a lot) but it's still not a complete solution since we don't know the value of "size" in resolutions[z] = size / Math.pow(2, z).

It did however put me on the right track. Here's how I figured out the resolutions to use in my QWC2 themesConfig.json file.

The themesConfig.json example on the QWC2 download site shows the resolutions for a WMTS that is in the same projection.

 {
    "type": "wmts",
    "url": "https://wxs.ign.fr/pratique/geoportail/wmts",
    "title": "IGN",
    "name": "GEOGRAPHICALGRIDSYSTEMS.MAPS",
    "format": "image/jpeg",
    "style": "normal",
    "originX": -20037508,
    "originY": 20037508,
    "projection": "EPSG:3857",
    "resolutions": [
      156543.03392804097,
      78271.51696402048,
      39135.75848201024,
      19567.87924100512,
      9783.93962050256,
      4891.96981025128,
      2445.98490512564,
      1222.99245256282,
      611.49622628141,
      305.748113140705,
      152.8740565703525,
      76.43702828517625,
      38.21851414258813,
      19.109257071294063,
      9.554628535647032,
      4.777314267823516,
      2.388657133911758,
      1.194328566955879
    ],
    "tileSize": [256, 256],
    "requestEncoding": "KVP",
    "tileMatrixSet": "PM",
    "tileMatrixPrefix": "",
    "thumbnail": "ign.png",
    "attribution": "<a href=\"http://www.geoportail.fr/\" target=\"_blank\"><img src=\"https://api.ign.fr/geoportail/api/js/latest/theme/geoportal/img/logo_gp.gif\"></a>"
  }

So I tested my wmts with these resolutions and it worked until I got to a certain zoom lever. I figured the reason was the example has 18 resolutions but my WMTS has 22 scale denominators.

Since things worked for the 18 resolutions I had, the solution was as simple as doing a reverse calculation. I took the first 3 resolutions from the sample and divided them by the first 3 scale denominators I got from GetCapabilities.

156543.03392804097 / 559082264.02871787548065185547 = 0.00028
 78271.51696402048 / 279541132.01435887813568115234 = 0.00028
 39135.75848201024 / 139770566.00717940926551818848 = 0.00028

So clearly 0.00028 is a constant, all I had to do was multiply the last 4 scale denominators from my GetCapabilities by 0.00028 to get the 4 resolutions I was missing which are

      0.597164283
      0.298582142
      0.149291071
      0.074645535

The resolutions section of themesConfig.json for my WMTS is as follows, it works perfectly.

 "resolutions": [
      156543.03392804097,
      78271.51696402048,
      39135.75848201024,
      19567.87924100512,
      9783.93962050256,
      4891.96981025128,
      2445.98490512564,
      1222.99245256282,
      611.49622628141,
      305.748113140705,
      152.8740565703525,
      76.43702828517625,
      38.21851414258813,
      19.109257071294063,
      9.554628535647032,
      4.777314267823516,
      2.388657133911758,
      1.194328566955879,
      0.597164283,
      0.298582142,
      0.149291071,
      0.074645535
    ],    
1
3

Ideally, your client should calculate all it needs from the getcapabilties response. But, looking at the OpenLayer example the following code is usually used to calculate the resolutions array (assuming you are in EPGS:3857):

for (var z = 0; z < 14; ++z) {
      // generate resolutions and matrixIds arrays for this WMTS
      resolutions[z] = size / Math.pow(2, z);
      matrixIds[z] = z;
 }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.