Skip to content
Permalink
Browse files

Merge pull request #36420 from qgis-bot/backport-36399-to-release-3_12

[Backport release-3_12] Fix xyx OSM tiles too many downloads
  • Loading branch information
elpaso committed May 14, 2020
2 parents 8b10b33 + 940c50a commit 600cea27a5b1fe76df91e6c307d4234bf36394c6
@@ -161,6 +161,7 @@ Base class for processing filters like renderers, reprojector, resampler etc.
IdentifyText,
IdentifyHtml,
IdentifyFeature,
Prefetch,
};

QgsRasterInterface( QgsRasterInterface *input = 0 );
@@ -179,7 +180,7 @@ Returns a bitmask containing the supported capabilities

QString capabilitiesString() const;
%Docstring
Returns the above in friendly format.
Returns the raster interface capabilities in friendly format.
%End

virtual Qgis::DataType dataType( int bandNo ) const = 0;
@@ -1238,7 +1238,8 @@ int QgsGdalProvider::capabilities() const
| QgsRasterDataProvider::Size
| QgsRasterDataProvider::BuildPyramids
| QgsRasterDataProvider::Create
| QgsRasterDataProvider::Remove;
| QgsRasterDataProvider::Remove
| QgsRasterDataProvider::Prefetch;
if ( mDriverName != QLatin1String( "WMS" ) )
{
capability |= QgsRasterDataProvider::Size;
@@ -192,6 +192,7 @@ class CORE_EXPORT QgsRasterInterface
IdentifyText = 1 << 7, // WMS text
IdentifyHtml = 1 << 8, // WMS HTML
IdentifyFeature = 1 << 9, // WMS GML -> feature
Prefetch = 1 << 10, // allow prefetching of out-of-view images
};

QgsRasterInterface( QgsRasterInterface *input = nullptr );
@@ -208,7 +209,7 @@ class CORE_EXPORT QgsRasterInterface
}

/**
* Returns the above in friendly format.
* Returns the raster interface capabilities in friendly format.
*/
QString capabilitiesString() const;

@@ -64,6 +64,7 @@ void QgsRasterLayerRendererFeedback::onNewData()
///
QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRenderContext &rendererContext )
: QgsMapLayerRenderer( layer->id(), &rendererContext )
, mLayer( layer )
, mFeedback( new QgsRasterLayerRendererFeedback( this ) )
{
QgsMapToPixel mapToPixel = rendererContext.mapToPixel();
@@ -239,10 +240,12 @@ QgsRasterLayerRenderer::~QgsRasterLayerRenderer()

bool QgsRasterLayerRenderer::render()
{
if ( !mRasterViewPort )
return true; // outside of layer extent - nothing to do

//R->draw( mPainter, mRasterViewPort, &mMapToPixel );
// Skip rendering of out of view tiles (xyz)
if ( !mRasterViewPort || ( mLayer && renderContext()->testFlag( QgsRenderContext::Flag::RenderPreviewJob ) &&
mLayer->dataProvider() &&
!( mLayer->dataProvider()->capabilities() &
QgsRasterInterface::Capability::Prefetch ) ) )
return true;

QElapsedTimer time;
time.start();
@@ -80,6 +80,8 @@ class CORE_EXPORT QgsRasterLayerRenderer : public QgsMapLayerRenderer

QgsRasterPipe *mPipe = nullptr;

QgsRasterLayer *mLayer;

//! feedback class for cancellation and preview generation
QgsRasterLayerRendererFeedback *mFeedback = nullptr;

@@ -90,7 +90,7 @@ class QgsAmsProvider : public QgsRasterDataProvider

/* Inherited from QgsRasterInterface */
int bandCount() const override { return 1; }
int capabilities() const override { return Identify | IdentifyText | IdentifyFeature; }
int capabilities() const override { return Identify | IdentifyText | IdentifyFeature | Prefetch; }

/* Inherited from QgsRasterDataProvider */
QgsRectangle extent() const override { return mExtent; }
@@ -667,7 +667,8 @@ int QgsPostgresRasterProvider::capabilities() const
| QgsRasterDataProvider::Size
// TODO:| QgsRasterDataProvider::BuildPyramids
| QgsRasterDataProvider::Create
| QgsRasterDataProvider::Remove;
| QgsRasterDataProvider::Remove
| QgsRasterDataProvider::Prefetch;
return capability;
}

@@ -1220,6 +1220,7 @@ int QgsWcsProvider::capabilities() const
int capability = NoCapabilities;
capability |= QgsRasterDataProvider::Identify;
capability |= QgsRasterDataProvider::IdentifyValue;
capability |= QgsRasterDataProvider::Prefetch;

if ( mHasSize )
{
@@ -728,20 +728,24 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
return image;
}

QgsDebugMsgLevel( QStringLiteral( "layer extent: %1,%2 %3x%4" )
.arg( qgsDoubleToString( mLayerExtent.xMinimum() ),
qgsDoubleToString( mLayerExtent.yMinimum() ) )
.arg( mLayerExtent.width() )
.arg( mLayerExtent.height() ), 3
);
QgsDebugMsg( QStringLiteral( "layer extent: %1,%2,%3,%4 %5x%6" )
.arg( qgsDoubleToString( mLayerExtent.xMinimum() ),
qgsDoubleToString( mLayerExtent.yMinimum() ) )
.arg( qgsDoubleToString( mLayerExtent.xMaximum() ),
qgsDoubleToString( mLayerExtent.yMaximum() ) )
.arg( mLayerExtent.width() )
.arg( mLayerExtent.height() )
);

QgsDebugMsgLevel( QStringLiteral( "view extent: %1,%2 %3x%4 res:%5" )
.arg( qgsDoubleToString( viewExtent.xMinimum() ),
qgsDoubleToString( viewExtent.yMinimum() ) )
.arg( viewExtent.width() )
.arg( viewExtent.height() )
.arg( vres, 0, 'f' ), 3
);
QgsDebugMsg( QStringLiteral( "view extent: %1,%2,%3,%4 %5x%6 res:%7" )
.arg( qgsDoubleToString( viewExtent.xMinimum() ),
qgsDoubleToString( viewExtent.yMinimum() ) )
.arg( qgsDoubleToString( viewExtent.xMaximum() ),
qgsDoubleToString( viewExtent.yMaximum() ) )
.arg( viewExtent.width() )
.arg( viewExtent.height() )
.arg( vres, 0, 'f' )
);

QgsDebugMsgLevel( QStringLiteral( "tile matrix %1,%2 res:%3 tilesize:%4x%5 matrixsize:%6x%7 id:%8" )
.arg( tm->topLeft.x() ).arg( tm->topLeft.y() ).arg( tm->tres )
@@ -870,7 +874,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
p.setRenderHint( QPainter::SmoothPixmapTransform, false ); // let's not waste time with bilinear filtering

QList<TileImage> lowerResTiles, lowerResTiles2, higherResTiles;
// first we check lower resolution tiles: one level back, then two levels back (if there is still some are not covered),
// first we check lower resolution tiles: one level back, then two levels back (if there is still some area not covered),
// finally (in the worst case we use one level higher resolution tiles). This heuristic should give
// good overviews while not spending too much time drawing cached tiles from resolutions far away.
fetchOtherResTiles( tileMode, viewExtent, image->width(), missing, tm->tres, 1, lowerResTiles );
@@ -1796,7 +1800,6 @@ int QgsWmsProvider::capabilities() const
int capability = NoCapabilities;
bool canIdentify = false;


if ( mSettings.mTiled && mTileLayer )
{
QgsDebugMsgLevel( QStringLiteral( "Tiled." ), 2 );
@@ -1828,10 +1831,17 @@ int QgsWmsProvider::capabilities() const
capability = mCaps.identifyCapabilities();
if ( capability )
{
capability |= Identify;
capability |= Capability::Identify;
}
}

// Prevent prefetch of XYZ openstreetmap images
// See: https://github.com/qgis/QGIS/issues/34813
if ( !( mSettings.mTiled && mSettings.mXyz && dataSourceUri().contains( QStringLiteral( "openstreetmap.org" ) ) ) )
{
capability |= Capability::Prefetch;
}

QgsDebugMsgLevel( QStringLiteral( "capability = %1" ).arg( capability ), 2 );
return capability;
}
@@ -2820,16 +2830,20 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPointXY &point, QgsRa
tres = it.key();
tm = &it.value();

QgsDebugMsg( QStringLiteral( "layer extent: %1,%2 %3x%4" )
QgsDebugMsg( QStringLiteral( "layer extent: %1,%2,%3,%4 %5x%6" )
.arg( qgsDoubleToString( mLayerExtent.xMinimum() ),
qgsDoubleToString( mLayerExtent.yMinimum() ) )
.arg( qgsDoubleToString( mLayerExtent.xMaximum() ),
qgsDoubleToString( mLayerExtent.yMaximum() ) )
.arg( mLayerExtent.width() )
.arg( mLayerExtent.height() )
);

QgsDebugMsg( QStringLiteral( "view extent: %1,%2 %3x%4 res:%5" )
QgsDebugMsg( QStringLiteral( "view extent: %1,%2,%3,%4 %5x%6 res:%7" )
.arg( qgsDoubleToString( boundingBox.xMinimum() ),
qgsDoubleToString( boundingBox.yMinimum() ) )
.arg( qgsDoubleToString( boundingBox.xMaximum() ),
qgsDoubleToString( boundingBox.yMaximum() ) )
.arg( boundingBox.width() )
.arg( boundingBox.height() )
.arg( vres, 0, 'f' )

0 comments on commit 600cea2

Please sign in to comment.
You can’t perform that action at this time.