Skip to content
Permalink
Browse files

Ensure that raster layers set to a fixed time range are completely

skipped in render jobs outside that time range
  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent ff32502 commit 8dc2299d03c0543abbf013ecbd2dfd84cf0df97b
@@ -42,6 +42,7 @@
#include "qgssymbollayer.h"
#include "qgsvectorlayerutils.h"
#include "qgssymbollayerutils.h"
#include "qgsmaplayertemporalproperties.h"

///@cond PRIVATE

@@ -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;
@@ -87,6 +87,8 @@ class TestQgsMapRendererJob : public QObject

void vectorLayerBoundsWithReprojection();

void temporalRender();

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

@@ -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";
Binary file not shown.
Binary file not shown.

0 comments on commit 8dc2299

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