From 9f3fb2ac35721a2a24928787918b28bec42c9094 Mon Sep 17 00:00:00 2001 From: Blottiere Paul Date: Thu, 17 Jun 2021 14:32:56 +0200 Subject: [PATCH] WMS GetFeatureInfo and TIME parameter --- ...terdataprovidertemporalcapabilities.sip.in | 1 + ...gsrasterdataprovidertemporalcapabilities.h | 6 ++-- src/gui/qgsmaptoolidentify.cpp | 4 ++- .../src/app/testqgsmaptoolidentifyaction.cpp | 36 ++++++++++++++++++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/python/core/auto_generated/raster/qgsrasterdataprovidertemporalcapabilities.sip.in b/python/core/auto_generated/raster/qgsrasterdataprovidertemporalcapabilities.sip.in index 1d05bc0ca1d8..0965d514b080 100644 --- a/python/core/auto_generated/raster/qgsrasterdataprovidertemporalcapabilities.sip.in +++ b/python/core/auto_generated/raster/qgsrasterdataprovidertemporalcapabilities.sip.in @@ -94,6 +94,7 @@ Returns the requested temporal range. Intended to be used by the provider in fetching data. %End + }; /************************************************************************ diff --git a/src/core/raster/qgsrasterdataprovidertemporalcapabilities.h b/src/core/raster/qgsrasterdataprovidertemporalcapabilities.h index e1d9c105bb6c..14fa11929679 100644 --- a/src/core/raster/qgsrasterdataprovidertemporalcapabilities.h +++ b/src/core/raster/qgsrasterdataprovidertemporalcapabilities.h @@ -110,8 +110,6 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv */ const QgsDateTimeRange &requestedTemporalRange() const; - private: - /** * Sets the requested temporal \a range to retrieve when * returning data from the associated data provider. @@ -122,7 +120,9 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv * * \see requestedTemporalRange() */ - void setRequestedTemporalRange( const QgsDateTimeRange &range ); + void setRequestedTemporalRange( const QgsDateTimeRange &range ) SIP_SKIP; + + private: /** * Represents available data provider datetime range. diff --git a/src/gui/qgsmaptoolidentify.cpp b/src/gui/qgsmaptoolidentify.cpp index 1757e74ef87e..908880eaf274 100644 --- a/src/gui/qgsmaptoolidentify.cpp +++ b/src/gui/qgsmaptoolidentify.cpp @@ -896,7 +896,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList *results, Qg if ( !layer ) return false; - QgsRasterDataProvider *dprovider = layer->dataProvider(); + std::unique_ptr< QgsRasterDataProvider > dprovider( layer->dataProvider()->clone() ); if ( !dprovider ) return false; @@ -908,6 +908,8 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList *results, Qg { if ( !layer->temporalProperties()->isVisibleInTemporalRange( identifyContext.temporalRange() ) ) return false; + + dprovider->temporalCapabilities()->setRequestedTemporalRange( identifyContext.temporalRange() ); } QgsPointXY pointInCanvasCrs = point; diff --git a/tests/src/app/testqgsmaptoolidentifyaction.cpp b/tests/src/app/testqgsmaptoolidentifyaction.cpp index 948a7ddb5d28..5a143a0e985b 100644 --- a/tests/src/app/testqgsmaptoolidentifyaction.cpp +++ b/tests/src/app/testqgsmaptoolidentifyaction.cpp @@ -37,6 +37,7 @@ #include "qgsmapmouseevent.h" #include "qgsmaplayertemporalproperties.h" #include "qgsmeshlayertemporalproperties.h" +#include "qgsrasterlayertemporalproperties.h" #include @@ -58,6 +59,7 @@ class TestQgsMapToolIdentifyAction : public QObject void areaCalculation(); //test calculation of derived area attribute void identifyRasterFloat32(); // test pixel identification and decimal precision void identifyRasterFloat64(); // test pixel identification and decimal precision + void identifyRasterTemporal(); void identifyMesh(); // test identification for mesh layer void identifyVectorTile(); // test identification for vector tile layer void identifyInvalidPolygons(); // test selecting invalid polygons @@ -520,7 +522,12 @@ QString TestQgsMapToolIdentifyAction::testIdentifyRaster( QgsRasterLayer *layer, { std::unique_ptr< QgsMapToolIdentifyAction > action( new QgsMapToolIdentifyAction( canvas ) ); QgsPointXY mapPoint = canvas->getCoordinateTransform()->transform( xGeoref, yGeoref ); - QList result = action->identify( mapPoint.x(), mapPoint.y(), QList() << layer ); + QgsIdentifyContext identifyContext; + if ( canvas->mapSettings().isTemporal() ) + identifyContext.setTemporalRange( canvas->temporalRange() ); + + QList result = action->identify( mapPoint.x(), mapPoint.y(), QList() << layer, QgsMapToolIdentify::DefaultQgsSetting, identifyContext ); + if ( result.length() != 1 ) return QString(); return result[0].mAttributes[QStringLiteral( "Band 1" )]; @@ -565,6 +572,33 @@ TestQgsMapToolIdentifyAction::testIdentifyVectorTile( QgsVectorTileLayer *layer, return result; } +void TestQgsMapToolIdentifyAction::identifyRasterTemporal() +{ + //create a temporary layer + QString raster = QStringLiteral( TEST_DATA_DIR ) + "/raster/test.asc"; + std::unique_ptr< QgsRasterLayer> tempLayer( new QgsRasterLayer( raster ) ); + QVERIFY( tempLayer->isValid() ); + + // activate temporal properties + tempLayer->temporalProperties()->setIsActive( true ); + + QgsDateTimeRange range = QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ), QTime(), Qt::UTC ), + QDateTime( QDate( 2020, 3, 31 ), QTime(), Qt::UTC ) ); + qobject_cast< QgsRasterLayerTemporalProperties * >( tempLayer->temporalProperties() )->setFixedTemporalRange( range ); + + canvas->setExtent( QgsRectangle( 0, 0, 7, 1 ) ); + + // invalid temporal range on canvas + canvas->setTemporalRange( QgsDateTimeRange( QDateTime( QDate( 1950, 01, 01 ), QTime( 0, 0, 0 ), Qt::UTC ), + QDateTime( QDate( 1950, 01, 01 ), QTime( 1, 0, 0 ), Qt::UTC ) ) ); + QCOMPARE( testIdentifyRaster( tempLayer.get(), 0.5, 0.5 ), QString( "" ) ); + + // valid temporal range on canvas + canvas->setTemporalRange( QgsDateTimeRange( QDateTime( QDate( 1950, 01, 01 ), QTime( 0, 0, 0 ), Qt::UTC ), + QDateTime( QDate( 2050, 01, 01 ), QTime( 1, 0, 0 ), Qt::UTC ) ) ); + QCOMPARE( testIdentifyRaster( tempLayer.get(), 0.5, 0.5 ), QString( "-999.9" ) ); +} + void TestQgsMapToolIdentifyAction::identifyRasterFloat32() { //create a temporary layer