Skip to content

Commit b5d0c75

Browse files
committedJun 27, 2018
wms provider: avoid exceeding server limits by tiling the requests (implements #19150)
1 parent efe0fbf commit b5d0c75

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,10 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
622622
QImage *image = new QImage( pixelWidth, pixelHeight, QImage::Format_ARGB32 );
623623
image->fill( 0 );
624624

625-
if ( !mSettings.mTiled && mSettings.mMaxWidth == 0 && mSettings.mMaxHeight == 0 )
625+
int maxWidth = mCaps.mCapabilities.service.maxWidth == 0 ? std::numeric_limits<int>::max() : mCaps.mCapabilities.service.maxWidth;
626+
int maxHeight = mCaps.mCapabilities.service.maxHeight == 0 ? std::numeric_limits<int>::max() : mCaps.mCapabilities.service.maxHeight;
627+
628+
if ( !mSettings.mTiled && mSettings.mMaxWidth == 0 && mSettings.mMaxHeight == 0 && pixelWidth <= maxWidth && pixelHeight <= maxHeight )
626629
{
627630
QUrl url = createRequestUrlWMS( viewExtent, pixelWidth, pixelHeight );
628631

@@ -655,16 +658,19 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
655658

656659
tileMode = mTileLayer->tileMode;
657660
}
658-
else if ( mSettings.mMaxWidth != 0 && mSettings.mMaxHeight != 0 )
661+
else if ( ( mSettings.mMaxWidth != 0 && mSettings.mMaxHeight != 0 ) || pixelWidth > maxWidth || pixelHeight > maxHeight )
659662
{
663+
int w = mSettings.mMaxWidth != 0 && mSettings.mMaxWidth < maxWidth ? mSettings.mMaxWidth : maxWidth;
664+
int h = mSettings.mMaxHeight != 0 && mSettings.mMaxHeight < maxHeight ? mSettings.mMaxHeight : maxHeight;
665+
660666
// this is an ordinary WMS server, but the user requested tiled approach
661667
// so we will pretend it is a WMS-C server with just one tile matrix
662668
tempTm.reset( new QgsWmtsTileMatrix );
663669
tempTm->topLeft = QgsPointXY( mLayerExtent.xMinimum(), mLayerExtent.yMaximum() );
664-
tempTm->tileWidth = mSettings.mMaxWidth;
665-
tempTm->tileHeight = mSettings.mMaxHeight;
666-
tempTm->matrixWidth = std::ceil( mLayerExtent.width() / mSettings.mMaxWidth / vres );
667-
tempTm->matrixHeight = std::ceil( mLayerExtent.height() / mSettings.mMaxHeight / vres );
670+
tempTm->tileWidth = w;
671+
tempTm->tileHeight = h;
672+
tempTm->matrixWidth = std::ceil( mLayerExtent.width() / w / vres );
673+
tempTm->matrixHeight = std::ceil( mLayerExtent.height() / h / vres );
668674
tempTm->tres = vres;
669675
tm = tempTm.get();
670676

0 commit comments

Comments
 (0)
Please sign in to comment.