Raster rendering: enable provider-side resampling when available, and reprojection is done

This commit is contained in:
Even Rouault 2020-06-13 17:10:29 +02:00 committed by Nyall Dawson
parent df8dd11e40
commit 93bc7c2f04
17 changed files with 48 additions and 16 deletions

View File

@ -1,5 +1,5 @@
zone,deg2,sum,count,min,max,mean
6.00000000,0.00034585,5378373.70841217,"34585",85.50000000,243.00000000,155.51174522
4.00000000,0.00013848,1266379.78169250,"13848",86.30000305,93.90000153,91.44856887
3.00000000,0.00026132,4379265.06565094,"26132",111.69999695,232.43850708,167.58246845
1.00000000,0.00037290,4677866.67560577,"37290",85.00000000,219.19999695,125.44560675
6.00000000,0.00034577,5379991.47400665,"34577",85.50000000,243.00000000,155.59451294
4.00000000,0.00013913,1272219.50825500,"13913",86.30000305,93.90000153,91.44106291
3.00000000,0.00026070,4368361.01625824,"26070",111.69999695,232.43850708,167.56275475
1.00000000,0.00037291,4680372.30075836,"37291",85.00000000,219.19999695,125.50943393

1 zone deg2 sum count min max mean
2 6.00000000 0.00034585 0.00034577 5378373.70841217 5379991.47400665 34585 34577 85.50000000 243.00000000 155.51174522 155.59451294
3 4.00000000 0.00013848 0.00013913 1266379.78169250 1272219.50825500 13848 13913 86.30000305 93.90000153 91.44856887 91.44106291
4 3.00000000 0.00026132 0.00026070 4379265.06565094 4368361.01625824 26132 26070 111.69999695 232.43850708 167.58246845 167.56275475
5 1.00000000 0.00037290 0.00037291 4677866.67560577 4680372.30075836 37290 37291 85.00000000 219.19999695 125.44560675 125.50943393

View File

@ -1,5 +1,5 @@
zone,m2,sum,count,min,max,mean
6.00000000,3055987.38515208,6069863.29187775,"39025",85.50000000,243.00000000,155.53781658
4.00000000,1226310.37671958,1432050.30903625,"15660",86.30000305,93.90000153,91.44637989
3.00000000,2310490.91092664,4944274.10529327,"29505",111.69999695,232.43850708,167.57410965
1.00000000,3297568.96319678,5283155.23725128,"42110",85.00000000,219.19999695,125.46082254
6.00000000,3055987.38515208,6070816.17861176,"39025",85.50000000,243.00000000,155.56223392
4.00000000,1226310.37671958,1431734.66448212,"15660",86.30000305,93.90000153,91.42622379
3.00000000,2310490.91092664,4941275.88129425,"29505",111.69999695,231.73440552,167.47249216
1.00000000,3297568.96319678,5287336.89630127,"42110",85.00000000,219.19999695,125.56012577

1 zone m2 sum count min max mean
2 6.00000000 3055987.38515208 6069863.29187775 6070816.17861176 39025 85.50000000 243.00000000 155.53781658 155.56223392
3 4.00000000 1226310.37671958 1432050.30903625 1431734.66448212 15660 86.30000305 93.90000153 91.44637989 91.42622379
4 3.00000000 2310490.91092664 4944274.10529327 4941275.88129425 29505 111.69999695 232.43850708 231.73440552 167.57410965 167.47249216
5 1.00000000 3297568.96319678 5283155.23725128 5287336.89630127 42110 85.00000000 219.19999695 125.46082254 125.56012577

View File

@ -1773,7 +1773,7 @@ tests:
type: raster
results:
OUTPUT:
hash: cdf6edb6afcefc5e80d60fa213df17aae59423019240807f5a49b72d
hash: 9c7f3070ad53b98ad9f42c3f758546268000043e990fbb38495d3c86
type: rasterhash
- algorithm: native:rasterbooleanand
@ -1819,7 +1819,7 @@ tests:
type: raster
results:
OUTPUT:
hash: dfe0bfc934a9d2a8ab865ad77db4278067830ac8e6f0470a730ad434
hash: eb41f92cb1198f1e4bed71e4a78d4fe2d3b35462a3949588d85cc818
type: rasterhash
- algorithm: native:rasterlogicalor
@ -1888,7 +1888,7 @@ tests:
type: raster
results:
OUTPUT:
hash: 56c4396468098a6f421e14682e22bb9cbb14027ed97f99cb8f85f953
hash: 2cd2f073cf337264140c1e5e3f162d5d134a731a094f1e1109e3ce12
type: rasterhash
- algorithm: native:rasterlogicalor
@ -1911,7 +1911,7 @@ tests:
type: raster
results:
OUTPUT:
hash: f8f7a412274c3133aee7fc24e3e6df2ddb52c6bc82663dd25154d3be
hash: d344a9306b7453c3faaef4558a9187da5525b0c90c6a04502bf15f1b
type: rasterhash
- algorithm: native:rasterlogicalor
@ -1934,7 +1934,7 @@ tests:
type: raster
results:
OUTPUT:
hash: 6c09e13126e16a267e36c79b0eeba7761422da7bd0387125f4c823e6
hash: 4e395a2151aba7558efedd43a33c85bbaae451ebcccef9a6dac86de4
type: rasterhash
- algorithm: native:addxyfields

View File

@ -269,11 +269,22 @@ void QgsRasterLayer::draw( QPainter *theQPainter,
//
QgsRasterProjector *projector = mPipe.projector();
bool restoreOldResamplingStage = false;
QgsRasterPipe::ResamplingStage oldResamplingState = resamplingStage();
// TODO add a method to interface to get provider and get provider
// params in QgsRasterProjector
if ( projector )
{
// Force provider resampling if reprojection is needed
if ( mDataProvider != nullptr &&
( mDataProvider->providerCapabilities() & QgsRasterDataProvider::ProviderHintCanPerformProviderResampling ) &&
rasterViewPort->mSrcCRS != rasterViewPort->mDestCRS &&
oldResamplingState != QgsRasterPipe::ResamplingStage::Provider )
{
restoreOldResamplingStage = true;
setResamplingStage( QgsRasterPipe::ResamplingStage::Provider );
}
projector->setCrs( rasterViewPort->mSrcCRS, rasterViewPort->mDestCRS, rasterViewPort->mTransformContext );
}
@ -282,6 +293,11 @@ void QgsRasterLayer::draw( QPainter *theQPainter,
QgsRasterDrawer drawer( &iterator );
drawer.draw( theQPainter, rasterViewPort, qgsMapToPixel );
if ( restoreOldResamplingStage )
{
setResamplingStage( oldResamplingState );
}
QgsDebugMsgLevel( QStringLiteral( "total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
} //end of draw method

View File

@ -281,11 +281,21 @@ bool QgsRasterLayerRenderer::render()
//
QgsRasterProjector *projector = mPipe->projector();
bool restoreOldResamplingStage = false;
QgsRasterPipe::ResamplingStage oldResamplingState = mPipe->resamplingStage();
// TODO add a method to interface to get provider and get provider
// params in QgsRasterProjector
if ( projector )
{
// Force provider resampling if reprojection is needed
if ( ( mPipe->provider()->providerCapabilities() & QgsRasterDataProvider::ProviderHintCanPerformProviderResampling ) &&
mRasterViewPort->mSrcCRS != mRasterViewPort->mDestCRS &&
oldResamplingState != QgsRasterPipe::ResamplingStage::Provider )
{
restoreOldResamplingStage = true;
mPipe->setResamplingStage( QgsRasterPipe::ResamplingStage::Provider );
}
projector->setCrs( mRasterViewPort->mSrcCRS, mRasterViewPort->mDestCRS, mRasterViewPort->mTransformContext );
}
@ -294,6 +304,11 @@ bool QgsRasterLayerRenderer::render()
QgsRasterDrawer drawer( &iterator );
drawer.draw( renderContext()->painter(), mRasterViewPort, &renderContext()->mapToPixel(), mFeedback );
if ( restoreOldResamplingStage )
{
mPipe->setResamplingStage( oldResamplingState );
}
const QStringList errors = mFeedback->errors();
for ( const QString &error : errors )
{

View File

@ -119,11 +119,12 @@ ProjectorData::ProjectorData( const QgsRectangle &extent, int width, int height,
QgsRasterDataProvider *provider = dynamic_cast<QgsRasterDataProvider *>( input->sourceInput() );
if ( provider )
{
// If provider-side resampling is enabled, we will get a much better looking
// If provider-side resampling is possible, we will get a much better looking
// result by not requesting at the maximum resolution and then doing nearest
// resampling here. A real fix would be to do resampling during reprojection
// however.
if ( !provider->isProviderResamplingEnabled() && ( provider->capabilities() & QgsRasterDataProvider::Size ) )
if ( !( provider->providerCapabilities() & QgsRasterDataProvider::ProviderHintCanPerformProviderResampling ) &&
( provider->capabilities() & QgsRasterDataProvider::Size ) )
{
mMaxSrcXRes = provider->extent().width() / provider->xSize();
mMaxSrcYRes = provider->extent().height() / provider->ySize();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 KiB

After

Width:  |  Height:  |  Size: 214 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 KiB

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 KiB

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 KiB

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

After

Width:  |  Height:  |  Size: 204 KiB