1

I am setting up a WMTS client to consume tiles from tileserver.php.

To request a tile I need to pass in the identifier/layer, the zoom height, the col and row to the WMTS RESTful server and it will return the tile.

e.g. http://myip.com/tileserver/tileserver.php?/index.json?/identifier/{z}/{x}/{y}.png

In my test environment I can manually choose a zoom level and my test code will correctly calculate the col(x) and row(y). I then can use this information to request the image.

This all works as expected.

However, now I need to workout how to programmatically determine the zoom height(z).

E.g. as the user zooms in or out of an area, I will need to workout the appropriate zoom level to, in turn, request an image from the tile server at the zoom level that approximates what the user is expecting.

I assume, to workout the correct zoom level:

  1. Determine the current bounding box for the user (this will be model space in a cad program). I will use the bounding box to get the linear width / height of the location they are located (in CAD).

  2. Use the screen pixel size of the monitor to workout pixel per meter? Am I going in the right direction?

How can I do this?

4
  • Is there a Capabilities response on the server
    – nmtoken
    Commented Jul 6, 2021 at 5:51
  • Yes, the server works as I can test against it. I have updated my question, hopefully this clarifies my issue. :-)
    – scott_f
    Commented Jul 6, 2021 at 21:22
  • 1
    Does the service use a well known scale set ~ see appendix E of OpenGIS Web Map Tile Service Implementation Standard
    – nmtoken
    Commented Jul 7, 2021 at 8:40
  • Yes it does, EPSG 3857
    – scott_f
    Commented Jul 7, 2021 at 23:32

1 Answer 1

1

Ok, it has finally soaked in as to what the answer is.

I will note it here encase someone else needs to work this out and they don't want to waste days of their life and their employers money in trying to sort this.

TileSpan is what I was after. The TileSpan is the width of the image (tile) that is returned from the tileserver.

I will include the basic calculations below.

I need to use the zoom level that generates a tile with a TileSpan that is just larger than the width of the target area.

I will iterate the tile matrices to discover the correct tile matrix to use.

  1. Get the Capabilities document from the tileserver
  2. Iterate the appropriate tile matrix set and examine each child element (tile matrix)
  3. Calculate the TileSpan for each tile matrix to find the tile matrix that contains the first TileSpan that is just larger than the area on interest.
  4. Calculate the col (x) and row (y) and use the zoom level (z) or Identifier as it is called in the Capabilities document to request the image.

Here are the Tile Matrix calculations for TileSpan to clarify:

See page 22: https://portal.ogc.org/files/?artifact_id=35326[OpenGIS Web Map Tile Service Implementation Standard][1]

pixelSpan = scaleDenominator × 0.00028  / metersPerUnit(crs);
tileSpanX = tileWidth × pixelSpan; 
tileSpanY = tileHeight × pixelSpan;
tileMatrixMaxX = tileMatrixMinX + tileSpanX × matrixWidth;
tileMatrixMinY = tileMatrixMaxY - tileSpanY × matrixHeight;

This is my understanding so far. All those that knew the answer please do leave a comment if I have gotten something wrong.

I will update this answer as I improve my understanding.

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.