From 627d614e9a5d08c6a679dac25c018a1b6bfceccf Mon Sep 17 00:00:00 2001 From: vcloarec Date: Fri, 29 Nov 2024 09:07:29 +0100 Subject: [PATCH] fix tests and other minors --- Tests/core/CMakeLists.txt | 1 + Tests/core/reos_watershed_test.cpp | 24 ++++++++++++ .../comephore/reos_comephores_test.cpp | 39 +++++++++++++++++-- src/core/rainfall/reosgriddedrainitem.cpp | 5 +++ src/core/rainfall/reosgriddedrainitem.h | 2 + src/core/raster/reosrasterwatershed.h | 2 +- .../delft-FEWS/reosdelftfewswidget.cpp | 4 +- src/dataProviders/hec-dss/CMakeLists.txt | 2 + 8 files changed, 74 insertions(+), 5 deletions(-) diff --git a/Tests/core/CMakeLists.txt b/Tests/core/CMakeLists.txt index 55c6de342..8015d4625 100644 --- a/Tests/core/CMakeLists.txt +++ b/Tests/core/CMakeLists.txt @@ -75,6 +75,7 @@ SET(TESTS IF(WITH_HYDRAULIC_MODEL_SUPPORT) SET(TESTS + ${TESTS} reos_mesh_test.cpp ) ENDIF(WITH_HYDRAULIC_MODEL_SUPPORT) diff --git a/Tests/core/reos_watershed_test.cpp b/Tests/core/reos_watershed_test.cpp index 9f2aa0d8f..588646dda 100644 --- a/Tests/core/reos_watershed_test.cpp +++ b/Tests/core/reos_watershed_test.cpp @@ -46,6 +46,8 @@ class ReosWatersehdTest: public QObject void runoffhydrograph(); + void delineate_watershed(); + private: ReosModule rootModule; ReosGisEngine gisEngine; @@ -401,6 +403,28 @@ void ReosWatersehdTest::watershedDelineating() QVERIFY( itemModel.rowCount( itemModel.index( 0, 0, QModelIndex() ) ) == 2 ); //including residual watershed } +void ReosWatersehdTest::delineate_watershed() +{ + QString layerId = gisEngine.addRasterLayer( "/home/vincent/dev/vortex/data/SRTMGL1_France_SE.tif", QStringLiteral( "raster_DEM" ) ); + ReosMapExtent extent = ReosMapExtent( 661553.33, 1792732.0, 661780.44, 1792964.54 ); + extent.setCrs( ReosGisEngine::crsFromEPSG( 32620 ) ); + + const QString directionFilePath = "/home/vincent/dev/vortex/data/SRTMGL1_France_SE_dir.tif"; + QPolygonF dsLine; + dsLine << QPointF( 2.62316877380512858, 43.26591984771614818 ) + << QPointF( 2.62914772565076982, 43.26415514870655699 ) + << QPointF( 2.62914772565076982, 43.26415514870655699 ); + + ReosWatershedDelineating::DelineateResult res = ReosWatershedDelineating::delineateWatershed( + layerId, + directionFilePath, + dsLine, + ReosGisEngine::crsFromEPSG( 4326 ), + &gisEngine ); + + int a = 1; +} + void ReosWatersehdTest::delineateFromDirection() { QString layerId = gisEngine.addRasterLayer( test_file( "DEM_for_watershed.tif" ).c_str(), QStringLiteral( "raster_DEM" ) ); diff --git a/Tests/dataProviders/comephore/reos_comephores_test.cpp b/Tests/dataProviders/comephore/reos_comephores_test.cpp index 48b79ae85..89de83c9a 100644 --- a/Tests/dataProviders/comephore/reos_comephores_test.cpp +++ b/Tests/dataProviders/comephore/reos_comephores_test.cpp @@ -35,8 +35,12 @@ class ReosComephoreTest: public QObject void createRainfallFromNetCdf(); void netCdfFolder(); void timeWindow(); - void missingIndex(); + void griddedDataOnWatersed(); + + private: + ReosModule mRootModule; + ReosGisEngine *mGisEngine = nullptr; }; void ReosComephoreTest::createProvider() @@ -84,6 +88,7 @@ void ReosComephoreTest::createProvider() provider->calculateMinMax( min, max ); QCOMPARE( min, 0.1 ); QCOMPARE( max, 12.4 ); + } void ReosComephoreTest::createRainfallFromTif() @@ -344,11 +349,39 @@ void ReosComephoreTest::missingIndex() ReosWatershed ws( delineating, delineating.at( 0 ), ReosGisEngine::crsFromEPSG( 2154 ) ); std::unique_ptr onWs = std::unique_ptr( ReosSeriesRainfallFromGriddedOnWatershed::create( & ws, rainfall.get() ) ); +} + +void ReosComephoreTest::griddedDataOnWatersed() +{ + QVariantMap uriParam; + uriParam[QStringLiteral( "file-or-dir-path" )] = COMEPHORE_FILES_PATH + QStringLiteral( "/comephore_nc" ); + + bool ok = false; + const QString &uri = ReosDataProviderRegistery::instance()->buildUri( QStringLiteral( "comephore" ), ReosGriddedRainfall::staticType(), uriParam, ok ); + QVERIFY( ok ); + + std::unique_ptr griddedData = + std::make_unique( uri, QStringLiteral( "era5" ) ); + + + QPolygonF watershed_poly; + watershed_poly << QPointF( 279856., 6309772. ) + << QPointF( 346425., 6320051. ) + << QPointF( 348884., 6252486. ) + << QPointF( 283670., 6251741. ); + + ReosWatershed watershed; + mGisEngine->setCrs( ReosGisEngine::crsFromEPSG( 9794 ) ); + watershed.setGeographicalContext( mGisEngine ); + watershed.setDelineating( watershed_poly ); - double value = onWs->valueAt( 743 ); + std::unique_ptr gridOnWs( ReosSeriesFromGriddedDataOnWatershed::create( &watershed, griddedData.get() ) ); - int a = 1; + gridOnWs->preCalculate(); + QVector values = gridOnWs->constData(); + QCOMPARE( values.count(), 3624 ); + QCOMPARE( values.at( 58 ), 0.0001061439977543495 ); } diff --git a/src/core/rainfall/reosgriddedrainitem.cpp b/src/core/rainfall/reosgriddedrainitem.cpp index 9cd12d202..237e53835 100644 --- a/src/core/rainfall/reosgriddedrainitem.cpp +++ b/src/core/rainfall/reosgriddedrainitem.cpp @@ -80,6 +80,11 @@ ReosGriddedRainfall::~ReosGriddedRainfall() { } +QString ReosGriddedRainfall::type() const +{ + return staticType(); +} + ReosGriddedRainfall *ReosGriddedRainfall::loadGriddedRainfall( const QString &dataSource, const QString &providerKey, QObject *parent ) { std::unique_ptr ret = std::make_unique( dataSource, providerKey, parent ); diff --git a/src/core/rainfall/reosgriddedrainitem.h b/src/core/rainfall/reosgriddedrainitem.h index 76e048630..f12cbc8f7 100644 --- a/src/core/rainfall/reosgriddedrainitem.h +++ b/src/core/rainfall/reosgriddedrainitem.h @@ -38,6 +38,8 @@ class REOSCORE_EXPORT ReosGriddedRainfall : public ReosGriddedData ReosGriddedRainfall( const QString &dataSource, const QString &providerKey, QObject *parent = nullptr ); ~ReosGriddedRainfall(); + QString type() const override SIP_SKIP; + static ReosGriddedRainfall *loadGriddedRainfall( const QString &dataSource, const QString &providerKey, QObject *parent = nullptr ); //! Returns a pointer to the data provider diff --git a/src/core/raster/reosrasterwatershed.h b/src/core/raster/reosrasterwatershed.h index 84dc0e49a..ddc0d5dda 100755 --- a/src/core/raster/reosrasterwatershed.h +++ b/src/core/raster/reosrasterwatershed.h @@ -137,7 +137,7 @@ class REOSCORE_EXPORT ReosRasterWatershedFromDirectionAndDownStreamLine: public void start() override; void stop( bool b ) override; - //! Returns the raster watershed defined by this class after calculation + //! Returns the raster watershed defined by this instance after calculation ReosRasterWatershed::Watershed watershed() const; //! Returns the first defined cells, that is on the middle of the downstream line diff --git a/src/dataProviders/delft-FEWS/reosdelftfewswidget.cpp b/src/dataProviders/delft-FEWS/reosdelftfewswidget.cpp index 5e314930d..709eab028 100644 --- a/src/dataProviders/delft-FEWS/reosdelftfewswidget.cpp +++ b/src/dataProviders/delft-FEWS/reosdelftfewswidget.cpp @@ -90,6 +90,9 @@ ReosDataObject *ReosDelftFewsWidget::createData( QObject *parent ) const std::unique_ptr dataObject; ReosDelftFewsXMLProviderInterface *provider = nullptr; + if ( dataObject->dataProvider() ) + dataObject->dataProvider()->setMetadata( station.meta ); + if ( station.dataType() == ReosDelftFewsXMLHydrographProvider::dataType() ) { dataObject.reset( createHydrograph( parent ) ); @@ -108,7 +111,6 @@ ReosDataObject *ReosDelftFewsWidget::createData( QObject *parent ) const if ( provider ) { - provider->setMetadata( station.meta ); dataObject->setName( station.meta.value( QStringLiteral( "name" ) ).toString() ); return dataObject.release(); } diff --git a/src/dataProviders/hec-dss/CMakeLists.txt b/src/dataProviders/hec-dss/CMakeLists.txt index 5dbe8c95d..d56fd986a 100644 --- a/src/dataProviders/hec-dss/CMakeLists.txt +++ b/src/dataProviders/hec-dss/CMakeLists.txt @@ -21,11 +21,13 @@ SET(REOS_PROVIDER_HEC_DSS_HEADERS IF(WITH_GUI) SET(REOS_PROVIDER_HEC_DSS_SOURCES + ${REOS_PROVIDER_HEC_DSS_SOURCES} reosdssgriddedrainfallselector.cpp reosdssprovideruriwidget.cpp ) SET(REOS_PROVIDER_HEC_DSS_HEADERS + ${REOS_PROVIDER_HEC_DSS_HEADERS} reosdssgriddedrainfallselector.h reosdssprovideruriwidget.h )