Skip to content

Commit d770525

Browse files
committed
[Bugfix][Server] WMTS: CRS can have axis inverted
The top left element has to respect the axis, like in WMS 1.3.0.
1 parent dd18e8f commit d770525

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

src/server/services/wmts/qgswmtsgetcapabilities.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,16 @@ namespace QgsWmts
540540
tmElement.appendChild( tmScaleDenomElem );
541541

542542
QDomElement tmTopLeftCornerElem = doc.createElement( QStringLiteral( "TopLeftCorner" ) );
543-
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.left, 6 ) + ' ' + qgsDoubleToString( tm.top, 6 ) );
544-
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
543+
if ( tms.hasAxisInverted )
544+
{
545+
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.top, 6 ) + ' ' + qgsDoubleToString( tm.left, 6 ) );
546+
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
547+
}
548+
else
549+
{
550+
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.left, 6 ) + ' ' + qgsDoubleToString( tm.top, 6 ) );
551+
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
552+
}
545553
tmElement.appendChild( tmTopLeftCornerElem );
546554

547555
QDomElement tmTileWidthElem = doc.createElement( QStringLiteral( "TileWidth" ) );

src/server/services/wmts/qgswmtsutils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ namespace QgsWmts
9696
}
9797

9898
tmi.unit = crs.mapUnits();
99+
tmi.hasAxisInverted = crs.hasAxisInverted();
99100

100101
// calculate tile matrix scale denominator
101102
double scaleDenominator = 0.0;
@@ -183,6 +184,7 @@ namespace QgsWmts
183184
tms.ref = tmi.ref;
184185
tms.extent = extent;
185186
tms.unit = unit;
187+
tms.hasAxisInverted = tmi.hasAxisInverted;
186188
tms.tileMatrixList = tileMatrixList;
187189

188190
return tms;
@@ -641,7 +643,7 @@ namespace QgsWmts
641643
double maxx = tm.left + ( tc + 1 ) * ( tileSize * res );
642644
double maxy = tm.top - tr * ( tileSize * res );
643645
QString bbox;
644-
if ( tms.ref == "EPSG:4326" )
646+
if ( tms.hasAxisInverted )
645647
{
646648
bbox = qgsDoubleToString( miny, 6 ) + ',' +
647649
qgsDoubleToString( minx, 6 ) + ',' +
@@ -702,6 +704,7 @@ namespace QgsWmts
702704
tmi4326.extent = QgsRectangle( -180, -90, 180, 90 );
703705
tmi4326.scaleDenominator = 279541132.0143588675418869;
704706
tmi4326.unit = QgsUnitTypes::DistanceDegrees;
707+
tmi4326.hasAxisInverted = true;
705708
m[tmi4326.ref] = tmi4326;
706709

707710
return m;

src/server/services/wmts/qgswmtsutils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ namespace QgsWmts
4343

4444
QgsUnitTypes::DistanceUnit unit = QgsUnitTypes::DistanceMeters;
4545

46+
bool hasAxisInverted = false;
47+
4648
double scaleDenominator = 0.0;
4749
};
4850

@@ -69,6 +71,8 @@ namespace QgsWmts
6971

7072
QgsUnitTypes::DistanceUnit unit = QgsUnitTypes::DistanceMeters;
7173

74+
bool hasAxisInverted = false;
75+
7276
QList< tileMatrixDef > tileMatrixList;
7377
};
7478

tests/testdata/qgis_server/wmts_getcapabilities.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ Content-Type: text/xml; charset=utf-8
939939
<TileMatrix>
940940
<ows:Identifier>0</ows:Identifier>
941941
<ScaleDenominator>279541132.014359</ScaleDenominator>
942-
<TopLeftCorner>-180 90</TopLeftCorner>
942+
<TopLeftCorner>90 -180</TopLeftCorner>
943943
<TileWidth>256</TileWidth>
944944
<TileHeight>256</TileHeight>
945945
<MatrixWidth>2</MatrixWidth>
@@ -948,7 +948,7 @@ Content-Type: text/xml; charset=utf-8
948948
<TileMatrix>
949949
<ows:Identifier>1</ows:Identifier>
950950
<ScaleDenominator>139770566.007179</ScaleDenominator>
951-
<TopLeftCorner>-180 90</TopLeftCorner>
951+
<TopLeftCorner>90 -180</TopLeftCorner>
952952
<TileWidth>256</TileWidth>
953953
<TileHeight>256</TileHeight>
954954
<MatrixWidth>4</MatrixWidth>
@@ -957,7 +957,7 @@ Content-Type: text/xml; charset=utf-8
957957
<TileMatrix>
958958
<ows:Identifier>2</ows:Identifier>
959959
<ScaleDenominator>69885283.00359</ScaleDenominator>
960-
<TopLeftCorner>-180 90</TopLeftCorner>
960+
<TopLeftCorner>90 -180</TopLeftCorner>
961961
<TileWidth>256</TileWidth>
962962
<TileHeight>256</TileHeight>
963963
<MatrixWidth>8</MatrixWidth>
@@ -966,7 +966,7 @@ Content-Type: text/xml; charset=utf-8
966966
<TileMatrix>
967967
<ows:Identifier>3</ows:Identifier>
968968
<ScaleDenominator>34942641.501795</ScaleDenominator>
969-
<TopLeftCorner>-180 90</TopLeftCorner>
969+
<TopLeftCorner>90 -180</TopLeftCorner>
970970
<TileWidth>256</TileWidth>
971971
<TileHeight>256</TileHeight>
972972
<MatrixWidth>16</MatrixWidth>
@@ -975,7 +975,7 @@ Content-Type: text/xml; charset=utf-8
975975
<TileMatrix>
976976
<ows:Identifier>4</ows:Identifier>
977977
<ScaleDenominator>17471320.750897</ScaleDenominator>
978-
<TopLeftCorner>-180 90</TopLeftCorner>
978+
<TopLeftCorner>90 -180</TopLeftCorner>
979979
<TileWidth>256</TileWidth>
980980
<TileHeight>256</TileHeight>
981981
<MatrixWidth>32</MatrixWidth>
@@ -984,7 +984,7 @@ Content-Type: text/xml; charset=utf-8
984984
<TileMatrix>
985985
<ows:Identifier>5</ows:Identifier>
986986
<ScaleDenominator>8735660.375449</ScaleDenominator>
987-
<TopLeftCorner>-180 90</TopLeftCorner>
987+
<TopLeftCorner>90 -180</TopLeftCorner>
988988
<TileWidth>256</TileWidth>
989989
<TileHeight>256</TileHeight>
990990
<MatrixWidth>64</MatrixWidth>
@@ -993,7 +993,7 @@ Content-Type: text/xml; charset=utf-8
993993
<TileMatrix>
994994
<ows:Identifier>6</ows:Identifier>
995995
<ScaleDenominator>4367830.187724</ScaleDenominator>
996-
<TopLeftCorner>-180 90</TopLeftCorner>
996+
<TopLeftCorner>90 -180</TopLeftCorner>
997997
<TileWidth>256</TileWidth>
998998
<TileHeight>256</TileHeight>
999999
<MatrixWidth>128</MatrixWidth>
@@ -1002,7 +1002,7 @@ Content-Type: text/xml; charset=utf-8
10021002
<TileMatrix>
10031003
<ows:Identifier>7</ows:Identifier>
10041004
<ScaleDenominator>2183915.093862</ScaleDenominator>
1005-
<TopLeftCorner>-180 90</TopLeftCorner>
1005+
<TopLeftCorner>90 -180</TopLeftCorner>
10061006
<TileWidth>256</TileWidth>
10071007
<TileHeight>256</TileHeight>
10081008
<MatrixWidth>256</MatrixWidth>
@@ -1011,7 +1011,7 @@ Content-Type: text/xml; charset=utf-8
10111011
<TileMatrix>
10121012
<ows:Identifier>8</ows:Identifier>
10131013
<ScaleDenominator>1091957.546931</ScaleDenominator>
1014-
<TopLeftCorner>-180 90</TopLeftCorner>
1014+
<TopLeftCorner>90 -180</TopLeftCorner>
10151015
<TileWidth>256</TileWidth>
10161016
<TileHeight>256</TileHeight>
10171017
<MatrixWidth>512</MatrixWidth>
@@ -1020,7 +1020,7 @@ Content-Type: text/xml; charset=utf-8
10201020
<TileMatrix>
10211021
<ows:Identifier>9</ows:Identifier>
10221022
<ScaleDenominator>545978.773466</ScaleDenominator>
1023-
<TopLeftCorner>-180 90</TopLeftCorner>
1023+
<TopLeftCorner>90 -180</TopLeftCorner>
10241024
<TileWidth>256</TileWidth>
10251025
<TileHeight>256</TileHeight>
10261026
<MatrixWidth>1024</MatrixWidth>
@@ -1029,7 +1029,7 @@ Content-Type: text/xml; charset=utf-8
10291029
<TileMatrix>
10301030
<ows:Identifier>10</ows:Identifier>
10311031
<ScaleDenominator>272989.386733</ScaleDenominator>
1032-
<TopLeftCorner>-180 90</TopLeftCorner>
1032+
<TopLeftCorner>90 -180</TopLeftCorner>
10331033
<TileWidth>256</TileWidth>
10341034
<TileHeight>256</TileHeight>
10351035
<MatrixWidth>2048</MatrixWidth>
@@ -1038,7 +1038,7 @@ Content-Type: text/xml; charset=utf-8
10381038
<TileMatrix>
10391039
<ows:Identifier>11</ows:Identifier>
10401040
<ScaleDenominator>136494.693366</ScaleDenominator>
1041-
<TopLeftCorner>-180 90</TopLeftCorner>
1041+
<TopLeftCorner>90 -180</TopLeftCorner>
10421042
<TileWidth>256</TileWidth>
10431043
<TileHeight>256</TileHeight>
10441044
<MatrixWidth>4096</MatrixWidth>
@@ -1047,7 +1047,7 @@ Content-Type: text/xml; charset=utf-8
10471047
<TileMatrix>
10481048
<ows:Identifier>12</ows:Identifier>
10491049
<ScaleDenominator>68247.346683</ScaleDenominator>
1050-
<TopLeftCorner>-180 90</TopLeftCorner>
1050+
<TopLeftCorner>90 -180</TopLeftCorner>
10511051
<TileWidth>256</TileWidth>
10521052
<TileHeight>256</TileHeight>
10531053
<MatrixWidth>8192</MatrixWidth>
@@ -1056,7 +1056,7 @@ Content-Type: text/xml; charset=utf-8
10561056
<TileMatrix>
10571057
<ows:Identifier>13</ows:Identifier>
10581058
<ScaleDenominator>34123.673342</ScaleDenominator>
1059-
<TopLeftCorner>-180 90</TopLeftCorner>
1059+
<TopLeftCorner>90 -180</TopLeftCorner>
10601060
<TileWidth>256</TileWidth>
10611061
<TileHeight>256</TileHeight>
10621062
<MatrixWidth>16384</MatrixWidth>
@@ -1065,7 +1065,7 @@ Content-Type: text/xml; charset=utf-8
10651065
<TileMatrix>
10661066
<ows:Identifier>14</ows:Identifier>
10671067
<ScaleDenominator>17061.836671</ScaleDenominator>
1068-
<TopLeftCorner>-180 90</TopLeftCorner>
1068+
<TopLeftCorner>90 -180</TopLeftCorner>
10691069
<TileWidth>256</TileWidth>
10701070
<TileHeight>256</TileHeight>
10711071
<MatrixWidth>32768</MatrixWidth>
@@ -1074,7 +1074,7 @@ Content-Type: text/xml; charset=utf-8
10741074
<TileMatrix>
10751075
<ows:Identifier>15</ows:Identifier>
10761076
<ScaleDenominator>8530.918335</ScaleDenominator>
1077-
<TopLeftCorner>-180 90</TopLeftCorner>
1077+
<TopLeftCorner>90 -180</TopLeftCorner>
10781078
<TileWidth>256</TileWidth>
10791079
<TileHeight>256</TileHeight>
10801080
<MatrixWidth>65536</MatrixWidth>
@@ -1083,7 +1083,7 @@ Content-Type: text/xml; charset=utf-8
10831083
<TileMatrix>
10841084
<ows:Identifier>16</ows:Identifier>
10851085
<ScaleDenominator>4265.459168</ScaleDenominator>
1086-
<TopLeftCorner>-180 90</TopLeftCorner>
1086+
<TopLeftCorner>90 -180</TopLeftCorner>
10871087
<TileWidth>256</TileWidth>
10881088
<TileHeight>256</TileHeight>
10891089
<MatrixWidth>131072</MatrixWidth>
@@ -1092,7 +1092,7 @@ Content-Type: text/xml; charset=utf-8
10921092
<TileMatrix>
10931093
<ows:Identifier>17</ows:Identifier>
10941094
<ScaleDenominator>2132.729584</ScaleDenominator>
1095-
<TopLeftCorner>-180 90</TopLeftCorner>
1095+
<TopLeftCorner>90 -180</TopLeftCorner>
10961096
<TileWidth>256</TileWidth>
10971097
<TileHeight>256</TileHeight>
10981098
<MatrixWidth>262144</MatrixWidth>
@@ -1101,7 +1101,7 @@ Content-Type: text/xml; charset=utf-8
11011101
<TileMatrix>
11021102
<ows:Identifier>18</ows:Identifier>
11031103
<ScaleDenominator>1066.364792</ScaleDenominator>
1104-
<TopLeftCorner>-180 90</TopLeftCorner>
1104+
<TopLeftCorner>90 -180</TopLeftCorner>
11051105
<TileWidth>256</TileWidth>
11061106
<TileHeight>256</TileHeight>
11071107
<MatrixWidth>524288</MatrixWidth>
@@ -1110,7 +1110,7 @@ Content-Type: text/xml; charset=utf-8
11101110
<TileMatrix>
11111111
<ows:Identifier>19</ows:Identifier>
11121112
<ScaleDenominator>533.182396</ScaleDenominator>
1113-
<TopLeftCorner>-180 90</TopLeftCorner>
1113+
<TopLeftCorner>90 -180</TopLeftCorner>
11141114
<TileWidth>256</TileWidth>
11151115
<TileHeight>256</TileHeight>
11161116
<MatrixWidth>1048576</MatrixWidth>

0 commit comments

Comments
 (0)