Skip to content

Commit

Permalink
[Bugfix][Server] WMTS: CRS can have axis inverted
Browse files Browse the repository at this point in the history
The top left element has to respect the axis, like in WMS 1.3.0.
  • Loading branch information
rldhont committed Apr 19, 2019
1 parent dd18e8f commit d770525
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
12 changes: 10 additions & 2 deletions src/server/services/wmts/qgswmtsgetcapabilities.cpp
Expand Up @@ -540,8 +540,16 @@ namespace QgsWmts
tmElement.appendChild( tmScaleDenomElem );

QDomElement tmTopLeftCornerElem = doc.createElement( QStringLiteral( "TopLeftCorner" ) );
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.left, 6 ) + ' ' + qgsDoubleToString( tm.top, 6 ) );
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
if ( tms.hasAxisInverted )
{
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.top, 6 ) + ' ' + qgsDoubleToString( tm.left, 6 ) );
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
}
else
{
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.left, 6 ) + ' ' + qgsDoubleToString( tm.top, 6 ) );
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
}
tmElement.appendChild( tmTopLeftCornerElem );

QDomElement tmTileWidthElem = doc.createElement( QStringLiteral( "TileWidth" ) );
Expand Down
5 changes: 4 additions & 1 deletion src/server/services/wmts/qgswmtsutils.cpp
Expand Up @@ -96,6 +96,7 @@ namespace QgsWmts
}

tmi.unit = crs.mapUnits();
tmi.hasAxisInverted = crs.hasAxisInverted();

// calculate tile matrix scale denominator
double scaleDenominator = 0.0;
Expand Down Expand Up @@ -183,6 +184,7 @@ namespace QgsWmts
tms.ref = tmi.ref;
tms.extent = extent;
tms.unit = unit;
tms.hasAxisInverted = tmi.hasAxisInverted;
tms.tileMatrixList = tileMatrixList;

return tms;
Expand Down Expand Up @@ -641,7 +643,7 @@ namespace QgsWmts
double maxx = tm.left + ( tc + 1 ) * ( tileSize * res );
double maxy = tm.top - tr * ( tileSize * res );
QString bbox;
if ( tms.ref == "EPSG:4326" )
if ( tms.hasAxisInverted )
{
bbox = qgsDoubleToString( miny, 6 ) + ',' +
qgsDoubleToString( minx, 6 ) + ',' +
Expand Down Expand Up @@ -702,6 +704,7 @@ namespace QgsWmts
tmi4326.extent = QgsRectangle( -180, -90, 180, 90 );
tmi4326.scaleDenominator = 279541132.0143588675418869;
tmi4326.unit = QgsUnitTypes::DistanceDegrees;
tmi4326.hasAxisInverted = true;
m[tmi4326.ref] = tmi4326;

return m;
Expand Down
4 changes: 4 additions & 0 deletions src/server/services/wmts/qgswmtsutils.h
Expand Up @@ -43,6 +43,8 @@ namespace QgsWmts

QgsUnitTypes::DistanceUnit unit = QgsUnitTypes::DistanceMeters;

bool hasAxisInverted = false;

double scaleDenominator = 0.0;
};

Expand All @@ -69,6 +71,8 @@ namespace QgsWmts

QgsUnitTypes::DistanceUnit unit = QgsUnitTypes::DistanceMeters;

bool hasAxisInverted = false;

QList< tileMatrixDef > tileMatrixList;
};

Expand Down
40 changes: 20 additions & 20 deletions tests/testdata/qgis_server/wmts_getcapabilities.txt
Expand Up @@ -939,7 +939,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>0</ows:Identifier>
<ScaleDenominator>279541132.014359</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>2</MatrixWidth>
Expand All @@ -948,7 +948,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>1</ows:Identifier>
<ScaleDenominator>139770566.007179</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>4</MatrixWidth>
Expand All @@ -957,7 +957,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>2</ows:Identifier>
<ScaleDenominator>69885283.00359</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>8</MatrixWidth>
Expand All @@ -966,7 +966,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>3</ows:Identifier>
<ScaleDenominator>34942641.501795</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>16</MatrixWidth>
Expand All @@ -975,7 +975,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>4</ows:Identifier>
<ScaleDenominator>17471320.750897</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>32</MatrixWidth>
Expand All @@ -984,7 +984,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>5</ows:Identifier>
<ScaleDenominator>8735660.375449</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>64</MatrixWidth>
Expand All @@ -993,7 +993,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>6</ows:Identifier>
<ScaleDenominator>4367830.187724</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>128</MatrixWidth>
Expand All @@ -1002,7 +1002,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>7</ows:Identifier>
<ScaleDenominator>2183915.093862</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>256</MatrixWidth>
Expand All @@ -1011,7 +1011,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>8</ows:Identifier>
<ScaleDenominator>1091957.546931</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>512</MatrixWidth>
Expand All @@ -1020,7 +1020,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>9</ows:Identifier>
<ScaleDenominator>545978.773466</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>1024</MatrixWidth>
Expand All @@ -1029,7 +1029,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>10</ows:Identifier>
<ScaleDenominator>272989.386733</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>2048</MatrixWidth>
Expand All @@ -1038,7 +1038,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>11</ows:Identifier>
<ScaleDenominator>136494.693366</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>4096</MatrixWidth>
Expand All @@ -1047,7 +1047,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>12</ows:Identifier>
<ScaleDenominator>68247.346683</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>8192</MatrixWidth>
Expand All @@ -1056,7 +1056,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>13</ows:Identifier>
<ScaleDenominator>34123.673342</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>16384</MatrixWidth>
Expand All @@ -1065,7 +1065,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>14</ows:Identifier>
<ScaleDenominator>17061.836671</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>32768</MatrixWidth>
Expand All @@ -1074,7 +1074,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>15</ows:Identifier>
<ScaleDenominator>8530.918335</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>65536</MatrixWidth>
Expand All @@ -1083,7 +1083,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>16</ows:Identifier>
<ScaleDenominator>4265.459168</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>131072</MatrixWidth>
Expand All @@ -1092,7 +1092,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>17</ows:Identifier>
<ScaleDenominator>2132.729584</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>262144</MatrixWidth>
Expand All @@ -1101,7 +1101,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>18</ows:Identifier>
<ScaleDenominator>1066.364792</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>524288</MatrixWidth>
Expand All @@ -1110,7 +1110,7 @@ Content-Type: text/xml; charset=utf-8
<TileMatrix>
<ows:Identifier>19</ows:Identifier>
<ScaleDenominator>533.182396</ScaleDenominator>
<TopLeftCorner>-180 90</TopLeftCorner>
<TopLeftCorner>90 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>1048576</MatrixWidth>
Expand Down

0 comments on commit d770525

Please sign in to comment.