<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Vain tekstin\00E4 Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
span.Shkpostityyli17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.VaintekstinChar
        {mso-style-name:"Vain tekstin\00E4 Char";
        mso-style-priority:99;
        mso-style-link:"Vain tekstin\00E4";
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 2.0cm 70.85pt 2.0cm;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="FI" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">While playing with gdal_translate and WMST my colleague found that GDAL was picking a wrong DataWindow with<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">gdal_translate "WMTS:http://xx.yy.fi/foo/service?REQUEST=GetCapabilities&SERVICE=WMTS,layer=bar" bar.xml -of WMTS<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">After some thinking we started to believe that the reason may be in the wrong WGS84BoundingBox that this WMTS service puts into GetCapabilities<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><ows:WGS84BoundingBox><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><ows:LowerCorner>-6.38153862706 55.6179644952</ows:LowerCorner><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><ows:UpperCorner>60.3815386271 75.5825702342</ows:UpperCorner><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"></ows:WGS84BoundingBox><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">I checked with gdaltransform that longitude -6.38153862706 converts into the value that was used as the DataWindow UpperLeftX value:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><UpperLeftX>-1553364.000000402</UpperLeftX><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">However, the TopLeftCorner of the TileMatrix as it is defined in the GetCapabilities has a much smaller X value: -548576.000000<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><TileMatrix><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><ows:Identifier>0</ows:Identifier><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><ScaleDenominator>29257142.85714285820722579956</ScaleDenominator><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><TopLeftCorner>-548576.000000 8388608.000000</TopLeftCorner><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><TileWidth>256</TileWidth><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><TileHeight>256</TileHeight><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><MatrixWidth>1</MatrixWidth><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><MatrixHeight>1</MatrixHeight><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"></TileMatrix><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Probably because of the wrong UpperLeftX value was gdal_translate seems to think that the leftmost tile in this layer has a negative TileX value<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><TileX>-3924</TileX><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">By reading the WMTS standard the negative index values are not valid in WMTS:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">TileCol: Column index of tile matrix<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">Non negative integer type value between 0 and MatrixWidth-1 of this tile matrix defined in the ServiceMetadata document<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">BoundingBoxes does not seem to be mandatory in WMTS because they can be computed from other, mandatory parameters as it is written in the notes of Table 14 — Parts of TileMatrix data structure  <o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">“NOTE 7 The bounding box of a tile matrix is not supplied explicitly because it can be calculated from topLeftCorner, tileWidth, tileHeight and scaleDenominator.”<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">It feels that gdal_translate should never write a DataWindow that is bigger than the extents of the TileMatrix.   Perhaps BoundingBoxes, if they exist, could be used for limiting the maximum extent, like the TileMatrixSetLimits
 if they are found from the GetCapabilities. Or is there something special in WMTS that makes it much more comfortable for GDAL to trust in BoundingBoxes? Like the fact that different tile levels in WMTS may have different bounding boxes?<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">-Jukka Rahkonen-<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</body>
</html>