Skip to content

Commit 012faa6

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 0f16609 commit 012faa6

File tree

5 files changed

+60
-43
lines changed

5 files changed

+60
-43
lines changed

src/server/services/wmts/qgswmtsgetcapabilities.cpp

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

535535
QDomElement tmTopLeftCornerElem = doc.createElement( QStringLiteral( "TopLeftCorner" ) );
536-
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.left, 6 ) + ' ' + qgsDoubleToString( tm.top, 6 ) );
537-
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
536+
if ( tms.hasAxisInverted )
537+
{
538+
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.top, 6 ) + ' ' + qgsDoubleToString( tm.left, 6 ) );
539+
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
540+
}
541+
else
542+
{
543+
QDomText tmTopLeftCornerText = doc.createTextNode( qgsDoubleToString( tm.left, 6 ) + ' ' + qgsDoubleToString( tm.top, 6 ) );
544+
tmTopLeftCornerElem.appendChild( tmTopLeftCornerText );
545+
}
538546
tmElement.appendChild( tmTopLeftCornerElem );
539547

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

src/server/services/wmts/qgswmtsutils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ namespace QgsWmts
9999
}
100100

101101
tmi.unit = crs.mapUnits();
102+
tmi.hasAxisInverted = crs.hasAxisInverted();
102103

103104
// calculate tile matrix scale denominator
104105
double scaleDenominator = 0.0;
@@ -186,6 +187,7 @@ namespace QgsWmts
186187
tms.ref = tmi.ref;
187188
tms.extent = extent;
188189
tms.unit = unit;
190+
tms.hasAxisInverted = tmi.hasAxisInverted;
189191
tms.tileMatrixList = tileMatrixList;
190192

191193
return tms;
@@ -282,6 +284,7 @@ namespace QgsWmts
282284

283285
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crsStr );
284286
tmi.unit = crs.mapUnits();
287+
tmi.hasAxisInverted = crs.hasAxisInverted();
285288

286289
QgsCoordinateTransform crsTransform( QgsCoordinateReferenceSystem::fromOgcWmsCrs( GEO_EPSG_CRS_AUTHID ), crs, project );
287290
try
@@ -327,6 +330,7 @@ namespace QgsWmts
327330
tms.ref = tmi.ref;
328331
tms.extent = tmi.extent;
329332
tms.unit = tmi.unit;
333+
tms.hasAxisInverted = tmi.hasAxisInverted;
330334
tms.tileMatrixList = tileMatrixList;
331335

332336
tmsList.append( tms );
@@ -759,7 +763,7 @@ namespace QgsWmts
759763
double maxx = tm.left + ( tc + 1 ) * ( tileSize * res );
760764
double maxy = tm.top - tr * ( tileSize * res );
761765
QString bbox;
762-
if ( tms.ref == "EPSG:4326" )
766+
if ( tms.hasAxisInverted )
763767
{
764768
bbox = qgsDoubleToString( miny, 6 ) + ',' +
765769
qgsDoubleToString( minx, 6 ) + ',' +
@@ -820,6 +824,7 @@ namespace QgsWmts
820824
tmi4326.extent = QgsRectangle( -180, -90, 180, 90 );
821825
tmi4326.scaleDenominator = 279541132.0143588675418869;
822826
tmi4326.unit = QgsUnitTypes::DistanceDegrees;
827+
tmi4326.hasAxisInverted = true;
823828
m[tmi4326.ref] = tmi4326;
824829

825830
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
int lastLevel = -1;
@@ -71,6 +73,8 @@ namespace QgsWmts
7173

7274
QgsUnitTypes::DistanceUnit unit;
7375

76+
bool hasAxisInverted = false;
77+
7478
QList< tileMatrixDef > tileMatrixList;
7579
};
7680

tests/testdata/qgis_server/wmts_getcapabilities.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ Content-Type: text/xml; charset=utf-8
11911191
<TileMatrix>
11921192
<ows:Identifier>0</ows:Identifier>
11931193
<ScaleDenominator>279541132.014359</ScaleDenominator>
1194-
<TopLeftCorner>-180 90</TopLeftCorner>
1194+
<TopLeftCorner>90 -180</TopLeftCorner>
11951195
<TileWidth>256</TileWidth>
11961196
<TileHeight>256</TileHeight>
11971197
<MatrixWidth>2</MatrixWidth>
@@ -1200,7 +1200,7 @@ Content-Type: text/xml; charset=utf-8
12001200
<TileMatrix>
12011201
<ows:Identifier>1</ows:Identifier>
12021202
<ScaleDenominator>139770566.007179</ScaleDenominator>
1203-
<TopLeftCorner>-180 90</TopLeftCorner>
1203+
<TopLeftCorner>90 -180</TopLeftCorner>
12041204
<TileWidth>256</TileWidth>
12051205
<TileHeight>256</TileHeight>
12061206
<MatrixWidth>4</MatrixWidth>
@@ -1209,7 +1209,7 @@ Content-Type: text/xml; charset=utf-8
12091209
<TileMatrix>
12101210
<ows:Identifier>2</ows:Identifier>
12111211
<ScaleDenominator>69885283.00359</ScaleDenominator>
1212-
<TopLeftCorner>-180 90</TopLeftCorner>
1212+
<TopLeftCorner>90 -180</TopLeftCorner>
12131213
<TileWidth>256</TileWidth>
12141214
<TileHeight>256</TileHeight>
12151215
<MatrixWidth>8</MatrixWidth>
@@ -1218,7 +1218,7 @@ Content-Type: text/xml; charset=utf-8
12181218
<TileMatrix>
12191219
<ows:Identifier>3</ows:Identifier>
12201220
<ScaleDenominator>34942641.501795</ScaleDenominator>
1221-
<TopLeftCorner>-180 90</TopLeftCorner>
1221+
<TopLeftCorner>90 -180</TopLeftCorner>
12221222
<TileWidth>256</TileWidth>
12231223
<TileHeight>256</TileHeight>
12241224
<MatrixWidth>16</MatrixWidth>
@@ -1227,7 +1227,7 @@ Content-Type: text/xml; charset=utf-8
12271227
<TileMatrix>
12281228
<ows:Identifier>4</ows:Identifier>
12291229
<ScaleDenominator>17471320.750897</ScaleDenominator>
1230-
<TopLeftCorner>-180 90</TopLeftCorner>
1230+
<TopLeftCorner>90 -180</TopLeftCorner>
12311231
<TileWidth>256</TileWidth>
12321232
<TileHeight>256</TileHeight>
12331233
<MatrixWidth>32</MatrixWidth>
@@ -1236,7 +1236,7 @@ Content-Type: text/xml; charset=utf-8
12361236
<TileMatrix>
12371237
<ows:Identifier>5</ows:Identifier>
12381238
<ScaleDenominator>8735660.375449</ScaleDenominator>
1239-
<TopLeftCorner>-180 90</TopLeftCorner>
1239+
<TopLeftCorner>90 -180</TopLeftCorner>
12401240
<TileWidth>256</TileWidth>
12411241
<TileHeight>256</TileHeight>
12421242
<MatrixWidth>64</MatrixWidth>
@@ -1245,7 +1245,7 @@ Content-Type: text/xml; charset=utf-8
12451245
<TileMatrix>
12461246
<ows:Identifier>6</ows:Identifier>
12471247
<ScaleDenominator>4367830.187724</ScaleDenominator>
1248-
<TopLeftCorner>-180 90</TopLeftCorner>
1248+
<TopLeftCorner>90 -180</TopLeftCorner>
12491249
<TileWidth>256</TileWidth>
12501250
<TileHeight>256</TileHeight>
12511251
<MatrixWidth>128</MatrixWidth>
@@ -1254,7 +1254,7 @@ Content-Type: text/xml; charset=utf-8
12541254
<TileMatrix>
12551255
<ows:Identifier>7</ows:Identifier>
12561256
<ScaleDenominator>2183915.093862</ScaleDenominator>
1257-
<TopLeftCorner>-180 90</TopLeftCorner>
1257+
<TopLeftCorner>90 -180</TopLeftCorner>
12581258
<TileWidth>256</TileWidth>
12591259
<TileHeight>256</TileHeight>
12601260
<MatrixWidth>256</MatrixWidth>
@@ -1263,7 +1263,7 @@ Content-Type: text/xml; charset=utf-8
12631263
<TileMatrix>
12641264
<ows:Identifier>8</ows:Identifier>
12651265
<ScaleDenominator>1091957.546931</ScaleDenominator>
1266-
<TopLeftCorner>-180 90</TopLeftCorner>
1266+
<TopLeftCorner>90 -180</TopLeftCorner>
12671267
<TileWidth>256</TileWidth>
12681268
<TileHeight>256</TileHeight>
12691269
<MatrixWidth>512</MatrixWidth>
@@ -1272,7 +1272,7 @@ Content-Type: text/xml; charset=utf-8
12721272
<TileMatrix>
12731273
<ows:Identifier>9</ows:Identifier>
12741274
<ScaleDenominator>545978.773466</ScaleDenominator>
1275-
<TopLeftCorner>-180 90</TopLeftCorner>
1275+
<TopLeftCorner>90 -180</TopLeftCorner>
12761276
<TileWidth>256</TileWidth>
12771277
<TileHeight>256</TileHeight>
12781278
<MatrixWidth>1024</MatrixWidth>
@@ -1281,7 +1281,7 @@ Content-Type: text/xml; charset=utf-8
12811281
<TileMatrix>
12821282
<ows:Identifier>10</ows:Identifier>
12831283
<ScaleDenominator>272989.386733</ScaleDenominator>
1284-
<TopLeftCorner>-180 90</TopLeftCorner>
1284+
<TopLeftCorner>90 -180</TopLeftCorner>
12851285
<TileWidth>256</TileWidth>
12861286
<TileHeight>256</TileHeight>
12871287
<MatrixWidth>2048</MatrixWidth>
@@ -1290,7 +1290,7 @@ Content-Type: text/xml; charset=utf-8
12901290
<TileMatrix>
12911291
<ows:Identifier>11</ows:Identifier>
12921292
<ScaleDenominator>136494.693366</ScaleDenominator>
1293-
<TopLeftCorner>-180 90</TopLeftCorner>
1293+
<TopLeftCorner>90 -180</TopLeftCorner>
12941294
<TileWidth>256</TileWidth>
12951295
<TileHeight>256</TileHeight>
12961296
<MatrixWidth>4096</MatrixWidth>
@@ -1299,7 +1299,7 @@ Content-Type: text/xml; charset=utf-8
12991299
<TileMatrix>
13001300
<ows:Identifier>12</ows:Identifier>
13011301
<ScaleDenominator>68247.346683</ScaleDenominator>
1302-
<TopLeftCorner>-180 90</TopLeftCorner>
1302+
<TopLeftCorner>90 -180</TopLeftCorner>
13031303
<TileWidth>256</TileWidth>
13041304
<TileHeight>256</TileHeight>
13051305
<MatrixWidth>8192</MatrixWidth>
@@ -1308,7 +1308,7 @@ Content-Type: text/xml; charset=utf-8
13081308
<TileMatrix>
13091309
<ows:Identifier>13</ows:Identifier>
13101310
<ScaleDenominator>34123.673342</ScaleDenominator>
1311-
<TopLeftCorner>-180 90</TopLeftCorner>
1311+
<TopLeftCorner>90 -180</TopLeftCorner>
13121312
<TileWidth>256</TileWidth>
13131313
<TileHeight>256</TileHeight>
13141314
<MatrixWidth>16384</MatrixWidth>
@@ -1317,7 +1317,7 @@ Content-Type: text/xml; charset=utf-8
13171317
<TileMatrix>
13181318
<ows:Identifier>14</ows:Identifier>
13191319
<ScaleDenominator>17061.836671</ScaleDenominator>
1320-
<TopLeftCorner>-180 90</TopLeftCorner>
1320+
<TopLeftCorner>90 -180</TopLeftCorner>
13211321
<TileWidth>256</TileWidth>
13221322
<TileHeight>256</TileHeight>
13231323
<MatrixWidth>32768</MatrixWidth>
@@ -1326,7 +1326,7 @@ Content-Type: text/xml; charset=utf-8
13261326
<TileMatrix>
13271327
<ows:Identifier>15</ows:Identifier>
13281328
<ScaleDenominator>8530.918335</ScaleDenominator>
1329-
<TopLeftCorner>-180 90</TopLeftCorner>
1329+
<TopLeftCorner>90 -180</TopLeftCorner>
13301330
<TileWidth>256</TileWidth>
13311331
<TileHeight>256</TileHeight>
13321332
<MatrixWidth>65536</MatrixWidth>
@@ -1335,7 +1335,7 @@ Content-Type: text/xml; charset=utf-8
13351335
<TileMatrix>
13361336
<ows:Identifier>16</ows:Identifier>
13371337
<ScaleDenominator>4265.459168</ScaleDenominator>
1338-
<TopLeftCorner>-180 90</TopLeftCorner>
1338+
<TopLeftCorner>90 -180</TopLeftCorner>
13391339
<TileWidth>256</TileWidth>
13401340
<TileHeight>256</TileHeight>
13411341
<MatrixWidth>131072</MatrixWidth>
@@ -1344,7 +1344,7 @@ Content-Type: text/xml; charset=utf-8
13441344
<TileMatrix>
13451345
<ows:Identifier>17</ows:Identifier>
13461346
<ScaleDenominator>2132.729584</ScaleDenominator>
1347-
<TopLeftCorner>-180 90</TopLeftCorner>
1347+
<TopLeftCorner>90 -180</TopLeftCorner>
13481348
<TileWidth>256</TileWidth>
13491349
<TileHeight>256</TileHeight>
13501350
<MatrixWidth>262144</MatrixWidth>
@@ -1353,7 +1353,7 @@ Content-Type: text/xml; charset=utf-8
13531353
<TileMatrix>
13541354
<ows:Identifier>18</ows:Identifier>
13551355
<ScaleDenominator>1066.364792</ScaleDenominator>
1356-
<TopLeftCorner>-180 90</TopLeftCorner>
1356+
<TopLeftCorner>90 -180</TopLeftCorner>
13571357
<TileWidth>256</TileWidth>
13581358
<TileHeight>256</TileHeight>
13591359
<MatrixWidth>524288</MatrixWidth>
@@ -1362,7 +1362,7 @@ Content-Type: text/xml; charset=utf-8
13621362
<TileMatrix>
13631363
<ows:Identifier>19</ows:Identifier>
13641364
<ScaleDenominator>533.182396</ScaleDenominator>
1365-
<TopLeftCorner>-180 90</TopLeftCorner>
1365+
<TopLeftCorner>90 -180</TopLeftCorner>
13661366
<TileWidth>256</TileWidth>
13671367
<TileHeight>256</TileHeight>
13681368
<MatrixWidth>1048576</MatrixWidth>

0 commit comments

Comments
 (0)