Skip to content

Commit

Permalink
Ensure that raster layers set to a fixed time range are completely
Browse files Browse the repository at this point in the history
skipped in render jobs outside that time range
  • Loading branch information
nyalldawson committed Mar 13, 2020
1 parent ff32502 commit 8dc2299
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/qgsmaprendererjob.cpp
Expand Up @@ -42,6 +42,7 @@
#include "qgssymbollayer.h"
#include "qgsvectorlayerutils.h"
#include "qgssymbollayerutils.h"
#include "qgsmaplayertemporalproperties.h"

///@cond PRIVATE

Expand Down Expand Up @@ -295,6 +296,12 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter *painter, QgsLabelingEn
continue;
}

if ( mSettings.isTemporal() && ml->temporalProperties() && !ml->temporalProperties()->isVisibleInTemporalRange( mSettings.temporalRange() ) )
{
QgsDebugMsgLevel( QStringLiteral( "Layer not rendered because it is not visible within the map's time range" ), 3 );
continue;
}

QgsRectangle r1 = mSettings.visibleExtent(), r2;
r1.grow( mSettings.extentBuffer() );
QgsCoordinateTransform ct;
Expand Down
58 changes: 58 additions & 0 deletions tests/src/core/testqgsmaprendererjob.cpp
Expand Up @@ -87,6 +87,8 @@ class TestQgsMapRendererJob : public QObject

void vectorLayerBoundsWithReprojection();

void temporalRender();

private:
bool imageCheck( const QString &type, const QImage &image, int mismatchCount = 0 );

Expand Down Expand Up @@ -886,6 +888,62 @@ void TestQgsMapRendererJob::vectorLayerBoundsWithReprojection()
QVERIFY( imageCheck( QStringLiteral( "vector_layer_bounds_with_reprojection" ), img ) );
}

void TestQgsMapRendererJob::temporalRender()
{
std::unique_ptr< QgsRasterLayer > rasterLayer = qgis::make_unique< QgsRasterLayer >( TEST_DATA_DIR + QStringLiteral( "/raster_layer.tiff" ),
QStringLiteral( "raster" ), QStringLiteral( "gdal" ) );
QVERIFY( rasterLayer->isValid() );

QgsMapSettings mapSettings;
mapSettings.setExtent( rasterLayer->extent() );
mapSettings.setDestinationCrs( rasterLayer->crs() );
mapSettings.setOutputSize( QSize( 512, 512 ) );
mapSettings.setFlag( QgsMapSettings::DrawLabeling, false );
mapSettings.setOutputDpi( 96 );
mapSettings.setLayers( QList< QgsMapLayer * >() << rasterLayer.get() );

QgsMapRendererSequentialJob renderJob( mapSettings );
renderJob.start();
renderJob.waitForFinished();
QImage img = renderJob.renderedImage();
QVERIFY( imageCheck( QStringLiteral( "temporal_render_visible" ), img ) );

// set temporal properties for layer
rasterLayer->temporalProperties()->setIsActive( true );
rasterLayer->temporalProperties()->setMode( QgsRasterLayerTemporalProperties::ModeFixedTemporalRange );
rasterLayer->temporalProperties()->setFixedTemporalRange( QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ),
QDateTime( QDate( 2020, 1, 5 ) ) ) );

// should still be visible -- map render job isn't temporal
QgsMapRendererSequentialJob renderJob2( mapSettings );
renderJob2.start();
renderJob2.waitForFinished();
img = renderJob2.renderedImage();
QVERIFY( imageCheck( QStringLiteral( "temporal_render_visible" ), img ) );

// make render job temporal, outside of layer's fixed range
mapSettings.setIsTemporal( true );
mapSettings.setTemporalRange( QgsDateTimeRange( QDateTime( QDate( 2021, 1, 1 ) ),
QDateTime( QDate( 2021, 1, 5 ) ) ) );
// should no longer be visible
QgsMapRendererSequentialJob renderJob3( mapSettings );
renderJob3.start();
renderJob3.waitForFinished();
img = renderJob3.renderedImage();
QVERIFY( imageCheck( QStringLiteral( "temporal_render_invisible" ), img ) );

// temporal range ok for layer
mapSettings.setTemporalRange( QgsDateTimeRange( QDateTime( QDate( 2020, 1, 2 ) ),
QDateTime( QDate( 2020, 1, 3 ) ) ) );
// should be visible
QgsMapRendererSequentialJob renderJob4( mapSettings );
renderJob4.start();
renderJob4.waitForFinished();
img = renderJob4.renderedImage();
QVERIFY( imageCheck( QStringLiteral( "temporal_render_visible" ), img ) );

}

bool TestQgsMapRendererJob::imageCheck( const QString &testName, const QImage &image, int mismatchCount )
{
mReport += "<h2>" + testName + "</h2>\n";
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8dc2299

Please sign in to comment.