@@ -137,6 +137,7 @@ void QgsWmsProvider::parseUri( QString uri )
137
137
138
138
mIgnoreGetMapUrl = false ;
139
139
mIgnoreGetFeatureInfoUrl = false ;
140
+ mIgnoreAxisOrientation = false ;
140
141
141
142
QString layer;
142
143
@@ -182,6 +183,10 @@ void QgsWmsProvider::parseUri( QString uri )
182
183
{
183
184
mIgnoreGetFeatureInfoUrl = true ;
184
185
}
186
+ else if ( param == " AxisOrientation" )
187
+ {
188
+ mIgnoreAxisOrientation = true ;
189
+ }
185
190
}
186
191
}
187
192
else if ( item.startsWith ( " tileMatrixSet=" ) )
@@ -337,13 +342,6 @@ size_t QgsWmsProvider::layerCount() const
337
342
return 1 ; // XXX properly return actual number of layers
338
343
} // QgsWmsProvider::layerCount()
339
344
340
- #if 0
341
- bool QgsWmsProvider::hasTiles() const
342
- {
343
- return mCapabilities.capability.tileSetProfiles.size() > 0;
344
- }
345
- #endif
346
-
347
345
QString QgsWmsProvider::baseUrl () const
348
346
{
349
347
return mBaseUrl ;
@@ -534,7 +532,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
534
532
535
533
// according to the WMS spec for 1.3, some CRS have inverted axis
536
534
bool changeXY = false ;
537
- if ( mCapabilities .version == " 1.3.0" || mCapabilities .version == " 1.3" )
535
+ if ( ! mIgnoreAxisOrientation && ( mCapabilities .version == " 1.3.0" || mCapabilities .version == " 1.3" ) )
538
536
{
539
537
// create CRS from string
540
538
QgsCoordinateReferenceSystem theSrs;
@@ -1070,10 +1068,10 @@ void QgsWmsProvider::tileReplyFinished()
1070
1068
r.width () / cr,
1071
1069
r.height () / cr );
1072
1070
1073
- QgsDebugMsg ( QString ( " tile reply: %1" ).arg ( reply->bytesAvailable () ) );
1071
+ QgsDebugMsg ( QString ( " tile reply: length %1" ).arg ( reply->bytesAvailable () ) );
1074
1072
QImage myLocalImage = QImage::fromData ( reply->readAll () );
1075
1073
1076
- // myLocalImage.save( QString( "%1/%2-tile-%3.png" ).arg( QDir::tempPath() ).arg( mTileReqNo ).arg( tileNo ) );
1074
+ myLocalImage.save ( QString ( " %1/%2-tile-%3.png" ).arg ( QDir::tempPath () ).arg ( mTileReqNo ).arg ( tileNo ) );
1077
1075
1078
1076
if ( !myLocalImage.isNull () )
1079
1077
{
@@ -1092,7 +1090,10 @@ void QgsWmsProvider::tileReplyFinished()
1092
1090
{
1093
1091
QgsMessageLog::logMessage ( tr ( " Returned image is flawed [%1]" ).arg ( reply->url ().toString () ), tr ( " WMS" ) );
1094
1092
}
1095
-
1093
+ }
1094
+ else
1095
+ {
1096
+ QgsMessageLog::logMessage ( tr ( " Reply to earlier tile request received too late [%1]" ).arg ( reply->url ().toString () ), tr ( " WMS" ) );
1096
1097
}
1097
1098
1098
1099
mTileReplies .removeOne ( reply );
@@ -1106,9 +1107,18 @@ void QgsWmsProvider::tileReplyFinished()
1106
1107
}
1107
1108
else
1108
1109
{
1110
+ mErrors ++;
1111
+ if ( mErrors < 100 )
1112
+ {
1113
+ QgsMessageLog::logMessage ( tr ( " Tile request failed [error:%1 url:%2]" ).arg ( reply->errorString () ).arg ( reply->url ().toString () ), tr ( " WMS" ) );
1114
+ }
1115
+ else if ( mErrors == 100 )
1116
+ {
1117
+ QgsMessageLog::logMessage ( tr ( " Not logging more than 100 request errors." ), tr ( " WMS" ) );
1118
+ }
1119
+
1109
1120
mTileReplies .removeOne ( reply );
1110
1121
reply->deleteLater ();
1111
- mErrors ++;
1112
1122
}
1113
1123
1114
1124
#ifdef QGISDEBUG
@@ -1200,9 +1210,18 @@ void QgsWmsProvider::cacheReplyFinished()
1200
1210
}
1201
1211
else
1202
1212
{
1213
+ mErrors ++;
1214
+ if ( mErrors < 100 )
1215
+ {
1216
+ QgsMessageLog::logMessage ( tr ( " Map request failed [error:%1 url:%2]" ).arg ( mCacheReply ->errorString () ).arg ( mCacheReply ->url ().toString () ), tr ( " WMS" ) );
1217
+ }
1218
+ else if ( mErrors == 100 )
1219
+ {
1220
+ QgsMessageLog::logMessage ( tr ( " Not logging more than 100 request errors." ), tr ( " WMS" ) );
1221
+ }
1222
+
1203
1223
mCacheReply ->deleteLater ();
1204
1224
mCacheReply = 0 ;
1205
- mErrors ++;
1206
1225
}
1207
1226
}
1208
1227
@@ -2446,8 +2465,10 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2446
2465
s.abstract = n0.firstChildElement ( " ows:Abstract" ).text ();
2447
2466
parseKeywords ( n0, s.keywords );
2448
2467
2468
+ QString supportedCRS = n0.firstChildElement ( " ows:SupportedCRS" ).text ();
2469
+
2449
2470
QgsCoordinateReferenceSystem crs;
2450
- crs.createFromOgcWmsCrs ( n0. firstChildElement ( " ows:SupportedCRS " ). text () );
2471
+ crs.createFromOgcWmsCrs ( supportedCRS );
2451
2472
2452
2473
s.wkScaleSet = n0.firstChildElement ( " WellKnownScaleSet" ).text ();
2453
2474
@@ -2476,7 +2497,13 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2476
2497
2477
2498
s.crs = crs.authid ();
2478
2499
2479
- QgsDebugMsg ( QString ( " tilematrix set: %1 (crs:%2; metersPerUnit:%3)" ).arg ( s.identifier ).arg ( s.crs ).arg ( metersPerUnit, 0 , ' f' ) );
2500
+ QgsDebugMsg ( QString ( " tilematrix set: %1 (supportedCRS:%2 crs:%3; metersPerUnit:%4 axisInverted:%5)" )
2501
+ .arg ( s.identifier )
2502
+ .arg ( supportedCRS )
2503
+ .arg ( s.crs )
2504
+ .arg ( metersPerUnit, 0 , ' f' )
2505
+ .arg ( !mIgnoreAxisOrientation && crs.axisInverted () ? " yes" : " no" )
2506
+ );
2480
2507
2481
2508
for ( QDomNode n1 = n0.firstChildElement ( " TileMatrix" );
2482
2509
!n1.isNull ();
@@ -2494,7 +2521,14 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2494
2521
QStringList topLeft = n1.firstChildElement ( " TopLeftCorner" ).text ().split ( " " );
2495
2522
if ( topLeft.size () == 2 )
2496
2523
{
2497
- m.topLeft .set ( topLeft[1 ].toDouble (), topLeft[0 ].toDouble () );
2524
+ if ( !mIgnoreAxisOrientation && crs.axisInverted () )
2525
+ {
2526
+ m.topLeft .set ( topLeft[1 ].toDouble (), topLeft[0 ].toDouble () );
2527
+ }
2528
+ else
2529
+ {
2530
+ m.topLeft .set ( topLeft[0 ].toDouble (), topLeft[1 ].toDouble () );
2531
+ }
2498
2532
}
2499
2533
else
2500
2534
{
@@ -2509,11 +2543,13 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2509
2543
2510
2544
double res = m.scaleDenom * 0.00028 / metersPerUnit;
2511
2545
2512
- QgsDebugMsg ( QString ( " %1: scale=%2 res=%3 tile=%4x%5 matrix=%6x%7" )
2546
+ QgsDebugMsg ( QString ( " %1: scale=%2 res=%3 tile=%4x%5 matrix=%6x%7 topLeft=%8 " )
2513
2547
.arg ( m.identifier )
2514
2548
.arg ( m.scaleDenom ).arg ( res )
2515
2549
.arg ( m.tileWidth ).arg ( m.tileHeight )
2516
- .arg ( m.matrixWidth ).arg ( m.matrixHeight ) );
2550
+ .arg ( m.matrixWidth ).arg ( m.matrixHeight )
2551
+ .arg ( m.topLeft .toString () )
2552
+ );
2517
2553
2518
2554
s.tileMatrices .insert ( res, m );
2519
2555
}
@@ -2635,6 +2671,8 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2635
2671
continue ;
2636
2672
}
2637
2673
2674
+ const QgsWmtsTileMatrixSet &tms = mTileMatrixSets [ sl.tileMatrixSet ];
2675
+
2638
2676
for ( QDomElement e2 = e1 .firstChildElement ( " TileMatrixSetLimits" ); !e2 .isNull (); e2 = e2 .nextSiblingElement ( " TileMatrixSetLimits" ) )
2639
2677
{
2640
2678
for ( QDomElement e3 = e2 .firstChildElement ( " TileMatrixLimits" ); !e3 .isNull (); e3 = e3 .nextSiblingElement ( " TileMatrixLimits" ) )
@@ -2643,17 +2681,56 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2643
2681
2644
2682
QString id = e3 .firstChildElement ( " TileMatrix" ).text ();
2645
2683
2646
- limit.minTileRow = e3 .firstChildElement ( " MinTileRow" ).text ().toInt ();
2647
- limit.maxTileRow = e3 .firstChildElement ( " MaxTileRow" ).text ().toInt ();
2648
- limit.minTileCol = e3 .firstChildElement ( " MinTileCol" ).text ().toInt ();
2649
- limit.maxTileCol = e3 .firstChildElement ( " MaxTileCol" ).text ().toInt ();
2684
+ bool isValid = false ;
2685
+ int matrixWidth = -1 , matrixHeight = -1 ;
2686
+ foreach ( const QgsWmtsTileMatrix &m, tms.tileMatrices )
2687
+ {
2688
+ isValid = m.identifier == id;
2689
+ if ( isValid )
2690
+ {
2691
+ matrixWidth = m.matrixWidth ;
2692
+ matrixHeight = m.matrixHeight ;
2693
+ break ;
2694
+ }
2695
+ }
2650
2696
2651
- QgsDebugMsg ( QString ( " TileMatrix id:%1 row:%2-%3 col:%4-%5" )
2697
+ if ( isValid )
2698
+ {
2699
+ limit.minTileRow = e3 .firstChildElement ( " MinTileRow" ).text ().toInt ();
2700
+ limit.maxTileRow = e3 .firstChildElement ( " MaxTileRow" ).text ().toInt ();
2701
+ limit.minTileCol = e3 .firstChildElement ( " MinTileCol" ).text ().toInt ();
2702
+ limit.maxTileCol = e3 .firstChildElement ( " MaxTileCol" ).text ().toInt ();
2703
+
2704
+ isValid =
2705
+ limit.minTileCol >= 0 && limit.minTileCol < matrixWidth &&
2706
+ limit.maxTileCol >= 0 && limit.maxTileCol < matrixWidth &&
2707
+ limit.minTileCol <= limit.maxTileCol &&
2708
+ limit.minTileRow >= 0 && limit.minTileRow < matrixHeight &&
2709
+ limit.maxTileRow >= 0 && limit.maxTileRow < matrixHeight &&
2710
+ limit.minTileRow <= limit.maxTileRow ;
2711
+ }
2712
+ else
2713
+ {
2714
+ QgsDebugMsg ( QString ( " TileMatrix id:%1 not found." ).arg ( id ) );
2715
+ }
2716
+
2717
+ QgsDebugMsg ( QString ( " TileMatrixLimit id:%1 row:%2-%3 col:%4-%5 %6" )
2652
2718
.arg ( id )
2653
2719
.arg ( limit.minTileRow ).arg ( limit.maxTileRow )
2654
2720
.arg ( limit.minTileCol ).arg ( limit.maxTileCol )
2721
+ .arg ( isValid ? " valid" : " INVALID" )
2655
2722
);
2656
- sl.limits .insert ( id, limit );
2723
+
2724
+ if ( isValid )
2725
+ {
2726
+ sl.limits .insert ( id, limit );
2727
+ }
2728
+ else
2729
+ {
2730
+ QgsDebugMsg ( QString ( " Limit of tileset %1 of matrix set %2 of layer %3 is invalid - ignored" )
2731
+ .arg ( id ).arg ( sl.tileMatrixSet ).arg ( l.identifier )
2732
+ );
2733
+ }
2657
2734
}
2658
2735
}
2659
2736
@@ -3618,7 +3695,7 @@ QStringList QgsWmsProvider::identifyAs( const QgsPoint& point, QString format )
3618
3695
3619
3696
// according to the WMS spec for 1.3, the order of x - and y - coordinates is inverted for geographical CRS
3620
3697
bool changeXY = false ;
3621
- if ( mCapabilities .version == " 1.3.0" || mCapabilities .version == " 1.3" )
3698
+ if ( ! mIgnoreAxisOrientation && ( mCapabilities .version == " 1.3.0" || mCapabilities .version == " 1.3" ) )
3622
3699
{
3623
3700
// create CRS from string
3624
3701
QgsCoordinateReferenceSystem theSrs;
0 commit comments