Skip to content
Permalink
Browse files

Raster rendering: enable provider-side resampling when available, and…

… reprojection is done
  • Loading branch information
rouault authored and nyalldawson committed Jun 19, 2020
1 parent df8dd11 commit 93bc7c2f041fb62f54c6e6248f8e9a32a93de886
Showing with 48 additions and 16 deletions.
  1. +4 −4 python/plugins/processing/tests/testdata/expected/raster_zonal_stats_reproj.csv
  2. +4 −4 python/plugins/processing/tests/testdata/expected/raster_zonal_stats_zone_crs_ref.csv
  3. +5 −5 python/plugins/processing/tests/testdata/qgis_algorithm_tests4.yaml
  4. +17 −1 src/core/raster/qgsrasterlayer.cpp
  5. +15 −0 src/core/raster/qgsrasterlayerrenderer.cpp
  6. +3 −2 src/core/raster/qgsrasterprojector.cpp
  7. BIN .../control_images/qgis_server/WMS_GetMap_Dimension_All_NoValue/WMS_GetMap_Dimension_All_NoValue.png
  8. BIN ...qgis_server/WMS_GetMap_Dimension_Elevation_MixValues/WMS_GetMap_Dimension_Elevation_MixValues.png
  9. BIN ..._server/WMS_GetMap_Dimension_Elevation_MultiValues/WMS_GetMap_Dimension_Elevation_MultiValues.png
  10. BIN ..._Dimension_Elevation_RangeElevation_Value/WMS_GetMap_Dimension_Elevation_RangeElevation_Value.png
  11. BIN ...is_server/WMS_GetMap_Dimension_Elevation_RangeValue/WMS_GetMap_Dimension_Elevation_RangeValue.png
  12. BIN ...GetMap_Dimension_Elevation_RangeValue_Filter/WMS_GetMap_Dimension_Elevation_RangeValue_Filter.png
  13. BIN ..._images/qgis_server/WMS_GetMap_Dimension_Elevation_Value/WMS_GetMap_Dimension_Elevation_Value.png
  14. BIN ...r/WMS_GetMap_Dimension_RangeElevation_MixValues/WMS_GetMap_Dimension_RangeElevation_MixValues.png
  15. BIN ...S_GetMap_Dimension_RangeElevation_MultiValues/WMS_GetMap_Dimension_RangeElevation_MultiValues.png
  16. BIN ...WMS_GetMap_Dimension_RangeElevation_RangeValue/WMS_GetMap_Dimension_RangeElevation_RangeValue.png
  17. BIN ...is_server/WMS_GetMap_Dimension_RangeElevation_Value/WMS_GetMap_Dimension_RangeElevation_Value.png
@@ -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,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
@@ -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
@@ -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

@@ -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 )
{
@@ -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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 93bc7c2

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