Skip to content
Permalink
Browse files

Fix calculating closest wmst time when wmst uses a static list of dat…

…etime values

(cherry picked from commit 912786e)
  • Loading branch information
nyalldawson committed Feb 19, 2021
1 parent 107b61c commit 64ff2c989db8333ae1ce3320aad201f4d65ae1b6
Showing with 41 additions and 15 deletions.
  1. +28 −14 src/providers/wms/qgswmscapabilities.cpp
  2. +13 −1 tests/src/providers/testqgswmscapabilities.cpp
@@ -317,26 +317,40 @@ QDateTime QgsWmsSettings::findLeastClosestDateTime( const QDateTime &dateTime, b

for ( const QgsWmstExtentPair &pair : mTimeDimensionExtent.datesResolutionList )
{
if ( pair.dates.dateTimes.size() < 2 )
if ( pair.dates.dateTimes.empty() )
{
continue;
}
else if ( pair.dates.dateTimes.size() == 1 )
{
long long startSeconds = pair.dates.dateTimes.at( 0 ).toSecsSinceEpoch();

long long startSeconds = pair.dates.dateTimes.at( 0 ).toSecsSinceEpoch();
long long endSeconds = pair.dates.dateTimes.at( 1 ).toSecsSinceEpoch();
// if out of bounds
if ( seconds < startSeconds )
continue;

// if out of bounds
if ( seconds < startSeconds || seconds > endSeconds )
continue;
if ( seconds == endSeconds )
break;
closest = pair.dates.dateTimes.at( 0 );
}
else
{
long long startSeconds = pair.dates.dateTimes.at( 0 ).toSecsSinceEpoch();
long long endSeconds = pair.dates.dateTimes.at( 1 ).toSecsSinceEpoch();

long long resolutionSeconds = pair.resolution.interval();
// if out of bounds
if ( seconds < startSeconds || seconds > endSeconds )
continue;
if ( seconds == endSeconds )
break;

if ( resolutionSeconds <= 0 )
continue;
long long step = std::floor( ( seconds - startSeconds ) / resolutionSeconds );
long long resultSeconds = startSeconds + ( step * resolutionSeconds );
long long resolutionSeconds = pair.resolution.interval();

closest.setSecsSinceEpoch( resultSeconds );
if ( resolutionSeconds <= 0 )
continue;
long long step = std::floor( ( seconds - startSeconds ) / resolutionSeconds );
long long resultSeconds = startSeconds + ( step * resolutionSeconds );

closest.setSecsSinceEpoch( resultSeconds );
}
}

return closest;
@@ -226,8 +226,20 @@ class TestQgsWmsCapabilities: public QObject
QCOMPARE( extent.datesResolutionList.at( 6 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1972, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 7 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 7 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1974, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
}

QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1930, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1930, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1932, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1932, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1932, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1932, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1933, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1932, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1947, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1947, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1949, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1947, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1950, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1950, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1950, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1950, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1973, 12, 31 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1972, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1974, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1974, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 1974, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1974, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( settings.findLeastClosestDateTime( QDateTime( QDate( 2000, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) ), QDateTime( QDate( 1974, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
}

void wmsTemporalDimension_data()
{

0 comments on commit 64ff2c9

Please sign in to comment.