@@ -234,6 +234,11 @@ void QgsWmsProvider::parseUri( QString uri )
234
234
235
235
QString QgsWmsProvider::prepareUri ( QString uri ) const
236
236
{
237
+ if ( uri.contains ( " SERVICE=WMTS" ) || uri.contains ( " /WMTSCapabilities.xml" ) )
238
+ {
239
+ return uri;
240
+ }
241
+
237
242
if ( !uri.contains ( " ?" ) )
238
243
{
239
244
uri.append ( " ?" );
@@ -548,10 +553,10 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
548
553
549
554
// Bounding box in WMS format (Warning: does not work with scientific notation)
550
555
QString bbox = QString ( changeXY ? " %2,%1,%4,%3" : " %1,%2,%3,%4" )
551
- .arg ( viewExtent.xMinimum (), 0 , ' f' )
552
- .arg ( viewExtent.yMinimum (), 0 , ' f' )
553
- .arg ( viewExtent.xMaximum (), 0 , ' f' )
554
- .arg ( viewExtent.yMaximum (), 0 , ' f' );
556
+ .arg ( viewExtent.xMinimum (), 0 , ' f' , 16 )
557
+ .arg ( viewExtent.yMinimum (), 0 , ' f' , 16 )
558
+ .arg ( viewExtent.xMaximum (), 0 , ' f' , 16 )
559
+ .arg ( viewExtent.yMaximum (), 0 , ' f' , 16 );
555
560
556
561
mCachedImage = new QImage ( pixelWidth, pixelHeight, QImage::Format_ARGB32 );
557
562
mCachedImage ->fill ( 0 );
@@ -702,7 +707,6 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
702
707
double thMap = tm->tileHeight * tres;
703
708
QgsDebugMsg ( QString ( " tile map size: %1,%2" ).arg ( twMap, 0 , ' f' ).arg ( thMap, 0 , ' f' ) );
704
709
705
-
706
710
int minTileCol = 0 ;
707
711
int maxTileCol = tm->matrixWidth - 1 ;
708
712
int minTileRow = 0 ;
@@ -759,10 +763,10 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
759
763
QString turl;
760
764
turl += url.toString ();
761
765
turl += QString ( changeXY ? " &BBOX=%2,%1,%4,%3" : " &BBOX=%1,%2,%3,%4" )
762
- .arg ( tm->topLeft .x () + col * twMap, 0 , ' f' )
763
- .arg ( tm->topLeft .y () - ( row + 1 ) * thMap, 0 , ' f' )
764
- .arg ( tm->topLeft .x () + ( col + 1 ) * twMap, 0 , ' f' )
765
- .arg ( tm->topLeft .y () - row * thMap, 0 , ' f' );
766
+ .arg ( tm->topLeft .x () + col * twMap /* + twMap * 0.001 */ , 0 , ' f' , 16 )
767
+ .arg ( tm->topLeft .y () - ( row + 1 ) * thMap /* - thMap * 0.001 */ , 0 , ' f' , 16 )
768
+ .arg ( tm->topLeft .x () + ( col + 1 ) * twMap /* - twMap * 0.001 */ , 0 , ' f' , 16 )
769
+ .arg ( tm->topLeft .y () - row * thMap /* + thMap * 0.001 */ , 0 , ' f' , 16 );
766
770
767
771
QNetworkRequest request ( turl );
768
772
setAuthorization ( request );
@@ -964,17 +968,19 @@ void QgsWmsProvider::tileReplyFinished()
964
968
QRectF r = reply->request ().attribute ( static_cast <QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ) ).toRectF ();
965
969
966
970
#if QT_VERSION >= 0x40500
967
- QgsDebugMsg ( QString ( " tile reply %1 (%2) tile:%3 rect:%4,%5 %6x%7) fromcache:%8 error:%9" )
971
+ QgsDebugMsg ( QString ( " tile reply %1 (%2) tile:%3 rect:%4,%5 %6x%7) fromcache:%8 error:%9 url:%10 " )
968
972
.arg ( tileReqNo ).arg ( mTileReqNo ).arg ( tileNo )
969
973
.arg ( r.left (), 0 , ' f' ).arg ( r.bottom (), 0 , ' f' ).arg ( r.width (), 0 , ' f' ).arg ( r.height (), 0 , ' f' )
970
974
.arg ( fromCache )
971
975
.arg ( reply->errorString () )
976
+ .arg ( reply->url ().toString () )
972
977
);
973
978
#else
974
- QgsDebugMsg ( QString ( " tile reply %1 (%2) tile:%3 rect:%4,%5 %6x%7) error:%8" )
979
+ QgsDebugMsg ( QString ( " tile reply %1 (%2) tile:%3 rect:%4,%5 %6x%7) error:%8 url:%9 " )
975
980
.arg ( tileReqNo ).arg ( mTileReqNo ).arg ( tileNo )
976
981
.arg ( r.left (), 0 , ' f' ).arg ( r.bottom (), 0 , ' f' ).arg ( r.width (), 0 , ' f' ).arg ( r.height (), 0 , ' f' )
977
982
.arg ( reply->errorString () )
983
+ .arg ( reply->url ().toString () )
978
984
);
979
985
#endif
980
986
@@ -1202,7 +1208,12 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
1202
1208
1203
1209
if ( mHttpCapabilitiesResponse .isNull () || forceRefresh )
1204
1210
{
1205
- QString url = mBaseUrl + " SERVICE=WMS&REQUEST=GetCapabilities" ;
1211
+ QString url = mBaseUrl ;
1212
+ if ( !url.contains ( " SERVICE=WMTS" ) &&
1213
+ !url.contains ( " /WMTSCapabilities.xml" ) )
1214
+ {
1215
+ url += " SERVICE=WMS&REQUEST=GetCapabilities" ;
1216
+ }
1206
1217
1207
1218
mError = " " ;
1208
1219
@@ -2317,7 +2328,7 @@ void QgsWmsProvider::parseTileSetProfile( QDomElement const &e )
2317
2328
}
2318
2329
else if ( tagName == " Format" )
2319
2330
{
2320
- l.format = e1 .text ();
2331
+ l.formats << e1 .text ();
2321
2332
}
2322
2333
else if ( tagName == " BoundingBox" )
2323
2334
{
@@ -2574,12 +2585,17 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2574
2585
l.defaultStyle = s.identifier ;
2575
2586
}
2576
2587
2577
- l.format = e0 .firstChildElement ( " Format" ).text ();
2578
- l.infoFormat = e0 .firstChildElement ( " InfoFormat" ).text ();
2588
+ for ( QDomElement e1 = e0 .firstChildElement ( " Format" ); !e1 .isNull (); e1 = e1 .nextSiblingElement ( " Format" ) )
2589
+ {
2590
+ l.formats << e1 .text ();
2591
+ }
2592
+
2593
+ for ( QDomElement e1 = e0 .firstChildElement ( " InfoFormat" ); !e1 .isNull (); e1 = e1 .nextSiblingElement ( " InfoFormat" ) )
2594
+ {
2595
+ l.infoFormats << e1 .text ();
2596
+ }
2579
2597
2580
- for ( QDomElement e1 = e0 .firstChildElement ( " Dimension" );
2581
- !e1 .isNull ();
2582
- e1 = e1 .nextSiblingElement ( " Dimension" ) )
2598
+ for ( QDomElement e1 = e0 .firstChildElement ( " Dimension" ); !e1 .isNull (); e1 = e1 .nextSiblingElement ( " Dimension" ) )
2583
2599
{
2584
2600
QgsWmtsDimension d;
2585
2601
@@ -2603,49 +2619,49 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
2603
2619
l.dimensions .insert ( d.identifier , d );
2604
2620
}
2605
2621
2606
- for ( QDomElement e1 = e0 .firstChildElement ( " TileMatrixSetLink" ).firstChildElement ( " TileMatrixSet" );
2607
- !e1 .isNull ();
2608
- e1 = e1 .nextSiblingElement ( " TileMatrixSet" ) )
2622
+ for ( QDomElement e1 = e0 .firstChildElement ( " TileMatrixSetLink" ); !e1 .isNull (); e1 = e1 .nextSiblingElement ( " TileMatrixSetLink" ) )
2609
2623
{
2610
- QgsWmtsTileMatrixSetLink sl;
2611
-
2612
- sl.tileMatrixSet = e1 .text ();
2613
- if ( !mTileMatrixSets .contains ( sl.tileMatrixSet ) )
2624
+ for ( QDomElement e2 = e1 .firstChildElement ( " TileMatrixSet" ); !e2 .isNull (); e2 = e2 .nextSiblingElement ( " TileMatrixSet" ) )
2614
2625
{
2615
- QgsDebugMsg ( QString ( " tileMatrixSet %1 not found." ).arg ( id ) );
2616
- continue ;
2617
- }
2626
+ QgsWmtsTileMatrixSetLink sl;
2618
2627
2619
- for ( QDomElement e2 = e1 .firstChildElement ( " TileMatrixSetLimits" ).firstChildElement ( " TileMatrixLimits" );
2620
- !e2 .isNull ();
2621
- e2 = e2 .nextSiblingElement ( " TileMatrixLimits" ) )
2622
- {
2623
- QgsWmtsTileMatrixLimits limit;
2628
+ sl.tileMatrixSet = e2 .text ();
2629
+ if ( !mTileMatrixSets .contains ( sl.tileMatrixSet ) )
2630
+ {
2631
+ QgsDebugMsg ( QString ( " tileMatrixSet %1 not found." ).arg ( id ) );
2632
+ continue ;
2633
+ }
2624
2634
2625
- QString id = e2 .firstChildElement ( " TileMatrix" ).text ();
2635
+ for ( QDomElement e3 = e2 .firstChildElement ( " TileMatrixSetLimits" ); !e3 .isNull (); e3 = e3 .nextSiblingElement ( " TileMatrixSetLimits" ) )
2636
+ {
2637
+ for ( QDomElement e4 = e3 .firstChildElement ( " TileMatrixLimits" ); !e4 .isNull (); e4 = e4 .nextSiblingElement ( " TileMatrixLimits" ) )
2638
+ {
2639
+ QgsWmtsTileMatrixLimits limit;
2626
2640
2627
- limit.minTileRow = e2 .firstChildElement ( " MinTileRow" ).text ().toInt ();
2628
- limit.maxTileRow = e2 .firstChildElement ( " MaxTileRow" ).text ().toInt ();
2629
- limit.minTileCol = e2 .firstChildElement ( " MinTileCol" ).text ().toInt ();
2630
- limit.maxTileCol = e2 .firstChildElement ( " MaxTileCol" ).text ().toInt ();
2641
+ QString id = e4 .firstChildElement ( " TileMatrix" ).text ();
2631
2642
2632
- sl.limits .insert ( id, limit );
2633
- }
2643
+ limit.minTileRow = e4 .firstChildElement ( " MinTileRow" ).text ().toInt ();
2644
+ limit.maxTileRow = e4 .firstChildElement ( " MaxTileRow" ).text ().toInt ();
2645
+ limit.minTileCol = e4 .firstChildElement ( " MinTileCol" ).text ().toInt ();
2646
+ limit.maxTileCol = e4 .firstChildElement ( " MaxTileCol" ).text ().toInt ();
2634
2647
2635
- l.setLinks .insert ( id, sl );
2648
+ sl.limits .insert ( id, limit );
2649
+ }
2650
+ }
2651
+
2652
+ l.setLinks .insert ( sl.tileMatrixSet , sl );
2653
+ }
2636
2654
}
2637
2655
2638
- for ( QDomElement e1 = e0 .firstChildElement ( " ResourceURL" );
2639
- !e1 .isNull ();
2640
- e1 = e1 .nextSiblingElement ( " ResourceURL" ) )
2656
+ for ( QDomElement e1 = e0 .firstChildElement ( " ResourceURL" ); !e1 .isNull (); e1 = e1 .nextSiblingElement ( " ResourceURL" ) )
2641
2657
{
2642
- QString format = e1 . attribute ( " format" );
2643
- QString resourceType = e1 . attribute ( " resourceType" );
2644
- QString tmpl = e1 . attribute ( " template" );
2658
+ QString format = nodeAttribute ( e1 , " format" );
2659
+ QString resourceType = nodeAttribute ( e1 , " resourceType" );
2660
+ QString tmpl = nodeAttribute ( e1 , " template" );
2645
2661
2646
2662
if ( format.isEmpty () || resourceType.isEmpty () || tmpl.isEmpty () )
2647
2663
{
2648
- QgsDebugMsg ( QString ( " SKIPPING ResourcURL format=%1 resourceType=%2 template=%3" )
2664
+ QgsDebugMsg ( QString ( " SKIPPING ResourceURL format=%1 resourceType=%2 template=%3" )
2649
2665
.arg ( format )
2650
2666
.arg ( resourceType )
2651
2667
.arg ( tmpl ) ) ;
@@ -3614,10 +3630,10 @@ QStringList QgsWmsProvider::identifyAs( const QgsPoint& point, QString format )
3614
3630
3615
3631
// Compose request to WMS server
3616
3632
QString bbox = QString ( changeXY ? " %2,%1,%4,%3" : " %1,%2,%3,%4" )
3617
- .arg ( mCachedViewExtent .xMinimum (), 0 , ' f' )
3618
- .arg ( mCachedViewExtent .yMinimum (), 0 , ' f' )
3619
- .arg ( mCachedViewExtent .xMaximum (), 0 , ' f' )
3620
- .arg ( mCachedViewExtent .yMaximum (), 0 , ' f' );
3633
+ .arg ( mCachedViewExtent .xMinimum (), 0 , ' f' , 16 )
3634
+ .arg ( mCachedViewExtent .yMinimum (), 0 , ' f' , 16 )
3635
+ .arg ( mCachedViewExtent .xMaximum (), 0 , ' f' , 16 )
3636
+ .arg ( mCachedViewExtent .yMaximum (), 0 , ' f' , 16 );
3621
3637
3622
3638
// Test for which layers are suitable for querying with
3623
3639
for ( QStringList::const_iterator
@@ -3819,7 +3835,6 @@ QVector<QgsWmsSupportedFormat> QgsWmsProvider::supportedFormats()
3819
3835
QVector<QgsWmsSupportedFormat> formats;
3820
3836
QStringList mFormats , mLabels ;
3821
3837
3822
-
3823
3838
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats ();
3824
3839
3825
3840
if ( supportedFormats.contains ( " png" ) )
@@ -3855,6 +3870,22 @@ QVector<QgsWmsSupportedFormat> QgsWmsProvider::supportedFormats()
3855
3870
return formats;
3856
3871
}
3857
3872
3873
+ QString QgsWmsProvider::nodeAttribute ( const QDomElement &e, QString name, QString defValue )
3874
+ {
3875
+ if ( e.hasAttribute ( name ) )
3876
+ return e.attribute ( name );
3877
+
3878
+ QDomNamedNodeMap map ( e.attributes () );
3879
+ for ( int i = 0 ; i < map.size (); i++ )
3880
+ {
3881
+ QDomAttr attr ( map.item ( i ).toElement ().toAttr () );
3882
+ if ( attr.name ().compare ( name, Qt::CaseInsensitive ) == 0 )
3883
+ return attr.value ();
3884
+ }
3885
+
3886
+ return defValue;
3887
+ }
3888
+
3858
3889
void QgsWmsProvider::showMessageBox ( const QString& title, const QString& text )
3859
3890
{
3860
3891
QgsMessageOutput *message = QgsMessageOutput::createMessageOutput ();
@@ -3892,4 +3923,3 @@ QGISEXTERN bool isProvider()
3892
3923
{
3893
3924
return true ;
3894
3925
}
3895
-
0 commit comments