Skip to content

Commit

Permalink
Fix xyx OSM tiles too many downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed May 14, 2020
1 parent 8b10b33 commit 940c50a
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 27 deletions.
3 changes: 2 additions & 1 deletion python/core/auto_generated/raster/qgsrasterinterface.sip.in
Expand Up @@ -161,6 +161,7 @@ Base class for processing filters like renderers, reprojector, resampler etc.
IdentifyText,
IdentifyHtml,
IdentifyFeature,
Prefetch,
};

QgsRasterInterface( QgsRasterInterface *input = 0 );
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgsrasterinterface.h
Expand Up @@ -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 );
Expand All @@ -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;

Expand Down
11 changes: 7 additions & 4 deletions src/core/raster/qgsrasterlayerrenderer.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/core/raster/qgsrasterlayerrenderer.h
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsamsprovider.h
Expand Up @@ -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; }
Expand Down
3 changes: 2 additions & 1 deletion src/providers/postgres/raster/qgspostgresrasterprovider.cpp
Expand Up @@ -667,7 +667,8 @@ int QgsPostgresRasterProvider::capabilities() const
| QgsRasterDataProvider::Size
// TODO:| QgsRasterDataProvider::BuildPyramids
| QgsRasterDataProvider::Create
| QgsRasterDataProvider::Remove;
| QgsRasterDataProvider::Remove
| QgsRasterDataProvider::Prefetch;
return capability;
}

Expand Down
1 change: 1 addition & 0 deletions src/providers/wcs/qgswcsprovider.cpp
Expand Up @@ -1220,6 +1220,7 @@ int QgsWcsProvider::capabilities() const
int capability = NoCapabilities;
capability |= QgsRasterDataProvider::Identify;
capability |= QgsRasterDataProvider::IdentifyValue;
capability |= QgsRasterDataProvider::Prefetch;

if ( mHasSize )
{
Expand Down
50 changes: 32 additions & 18 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -1796,7 +1800,6 @@ int QgsWmsProvider::capabilities() const
int capability = NoCapabilities;
bool canIdentify = false;


if ( mSettings.mTiled && mTileLayer )
{
QgsDebugMsgLevel( QStringLiteral( "Tiled." ), 2 );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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' )
Expand Down

0 comments on commit 940c50a

Please sign in to comment.