Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added two match modes for wmst static temporal range updates
  • Loading branch information
Samweli authored and nyalldawson committed Apr 1, 2020
1 parent 7422d65 commit 88f039e
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 87 deletions.
Expand Up @@ -38,6 +38,8 @@ The ``enabled`` argument specifies whether the data provider has temporal capabi
MatchUsingWholeRange,
MatchExactUsingStartOfRange,
MatchExactUsingEndOfRange,
FindClosestMatchToStartOfRange,
FindClosestMatchToEndOfRange
};

IntervalHandlingMethod intervalHandlingMethod() const;
Expand Down
4 changes: 3 additions & 1 deletion src/core/raster/qgsrasterdataprovidertemporalcapabilities.h
Expand Up @@ -53,8 +53,10 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv
MatchUsingWholeRange, //!< Use an exact match to the whole temporal range
MatchExactUsingStartOfRange, //!< Match the start of the temporal range to a corresponding layer or band, and only use exact matching results
MatchExactUsingEndOfRange, //!< Match the end of the temporal range to a corresponding layer or band, and only use exact matching results
FindClosestMatchToStartOfRange, //! Match the start of the temporal range to the least previous closest datetime.
FindClosestMatchToEndOfRange //! Match the end of the temporal range to the least previous closest datetime.
};
// TODO -- add other methods, like "FindClosestMatchToStartOfRange", "FindClosestMatchToEndOfRange", etc
// TODO -- add other methods

/**
* Returns the desired method to use when resolving a temporal interval to matching
Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgsrasterlayerrenderer.cpp
Expand Up @@ -246,7 +246,10 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
}
}
else if ( mPipe->provider()->temporalCapabilities() )
{
mPipe->provider()->temporalCapabilities()->setRequestedTemporalRange( QgsDateTimeRange() );
mPipe->provider()->temporalCapabilities()->setIntervalHandlingMethod( layer->temporalProperties()->intervalHandlingMethod() );
}
}

QgsRasterLayerRenderer::~QgsRasterLayerRenderer()
Expand Down
11 changes: 2 additions & 9 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -1222,15 +1222,6 @@ void QgsRasterLayerProperties::updateSourceStaticTime()

void QgsRasterLayerProperties::setSourceStaticTimeState()
{
QLocale locale;

mStartStaticDateTimeEdit->setDisplayFormat(
locale.dateTimeFormat( QLocale::ShortFormat ) );
mEndStaticDateTimeEdit->setDisplayFormat(
locale.dateTimeFormat( QLocale::ShortFormat ) );
mReferenceDateTimeEdit->setDisplayFormat(
locale.dateTimeFormat( QLocale::ShortFormat ) );

if ( mRasterLayer->dataProvider() && mRasterLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
{
const QgsDateTimeRange availableProviderRange = mRasterLayer->dataProvider()->temporalCapabilities()->availableTemporalRange();
Expand Down Expand Up @@ -1290,6 +1281,8 @@ void QgsRasterLayerProperties::setSourceStaticTimeState()
mFetchModeComboBox->addItem( tr( "Use Whole Temporal Range" ), QgsRasterDataProviderTemporalCapabilities::MatchUsingWholeRange );
mFetchModeComboBox->addItem( tr( "Match to Start of Range" ), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingStartOfRange );
mFetchModeComboBox->addItem( tr( "Match to End of Range" ), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange );
mFetchModeComboBox->addItem( tr( "Previous Closest to Start of Range" ), QgsRasterDataProviderTemporalCapabilities::FindClosestMatchToStartOfRange );
mFetchModeComboBox->addItem( tr( "Previous Closest to End of Range" ), QgsRasterDataProviderTemporalCapabilities::FindClosestMatchToEndOfRange );
mFetchModeComboBox->setCurrentIndex( mFetchModeComboBox->findData( mRasterLayer->temporalProperties()->intervalHandlingMethod() ) );

const QString temporalSource = uri.param( QStringLiteral( "temporalSource" ) );
Expand Down
36 changes: 34 additions & 2 deletions src/providers/wms/qgswmscapabilities.cpp
Expand Up @@ -295,6 +295,7 @@ QList<QDateTime> QgsWmsSettings::dateTimesFromExtent( QgsWmstDimensionExtent dim
{
QDateTime first = QDateTime( pair.dates.dateTimes.at( 0 ) );
QDateTime last = QDateTime( pair.dates.dateTimes.at( 1 ) );
dates.append( first );

while ( first < last )
{
Expand Down Expand Up @@ -334,6 +335,37 @@ QDateTime QgsWmsSettings::addTime( QDateTime dateTime, QgsWmstResolution resolut
return resultDateTime;
}

QDateTime QgsWmsSettings::findLeastClosestDateTime( QDateTime dateTime )
{
QDateTime closest = dateTime;
long long min = LLONG_MAX;

if ( !dateTime.isValid() || mDateTimes.contains( dateTime ) )
return closest;

for ( QDateTime current : mDateTimes )
{
if ( !current.isValid() )
continue;

long long difference = dateTime.secsTo( current );

// The datetimes list is sorted, if difference is increasing or
// it is above zero means search is now looking for greater than
// datetimes then search will have to stop.
if ( difference > 0 || std::abs( difference ) > min )
break;

if ( std::abs( difference ) < min )
{
min = std::abs( difference );
closest = current;
}
}

return closest;
}

QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )
{
QgsWmstResolution resolution;
Expand Down Expand Up @@ -416,10 +448,10 @@ QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )

QDateTime QgsWmsSettings::parseWmstDateTimes( QString item )
{
// Standard item will have YYYY-MM-DDThh:mm:ss.SSSZ
// Standard item will have YYYY-MM-DDTHH:mm:ss.SSSZ
// format a Qt::ISODateWithMs

QString format = "YYYY-MM-DDThh:mm:ss.SSSZ";
QString format = "YYYY-MM-DDTHH:mm:ss.SSSZ";

// Check if it does not have time part
if ( !item.contains( 'T' ) )
Expand Down
8 changes: 8 additions & 0 deletions src/providers/wms/qgswmscapabilities.h
Expand Up @@ -785,6 +785,14 @@ class QgsWmsSettings

QDateTime addTime( QDateTime dateTime, QgsWmstResolution resolution );

/**
* Finds the least closest datetime from list of available datetimes
* with the given \a dateTime.
*
* Returns the passed \a dateTime if it is found in the available datetimes.
*/
QDateTime findLeastClosestDateTime( QDateTime dateTime );

protected:
QgsWmsParserSettings mParserSettings;

Expand Down
44 changes: 27 additions & 17 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -1086,21 +1086,7 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )
QgsDataSourceUri uri;
uri.setEncodedUri( dataSourceUri() );

if ( !range.isInfinite() )
{
switch ( temporalCapabilities()->intervalHandlingMethod() )
{
case QgsRasterDataProviderTemporalCapabilities::MatchUsingWholeRange:
break;
case QgsRasterDataProviderTemporalCapabilities::MatchExactUsingStartOfRange:
range = QgsDateTimeRange( range.begin(), range.begin() );
break;
case QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange:
range = QgsDateTimeRange( range.end(), range.end() );
break;
}
}
else
if ( range.isInfinite() )
{
if ( uri.hasParam( QStringLiteral( "time" ) ) &&
!uri.param( QStringLiteral( "time" ) ).isEmpty() )
Expand All @@ -1111,8 +1097,7 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )
QDateTime start = QDateTime::fromString( timeParts.at( 0 ), Qt::ISODateWithMs );
QDateTime end = QDateTime::fromString( timeParts.at( 1 ), Qt::ISODateWithMs );

if ( start == end )
range = QgsDateTimeRange( start, end );
range = QgsDateTimeRange( start, end );
}
}

Expand All @@ -1121,6 +1106,31 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )

if ( range.begin().isValid() && range.end().isValid() )
{
switch ( temporalCapabilities()->intervalHandlingMethod() )
{
case QgsRasterDataProviderTemporalCapabilities::MatchUsingWholeRange:
break;
case QgsRasterDataProviderTemporalCapabilities::MatchExactUsingStartOfRange:
range = QgsDateTimeRange( range.begin(), range.begin() );
break;
case QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange:
range = QgsDateTimeRange( range.end(), range.end() );
break;
case QgsRasterDataProviderTemporalCapabilities::FindClosestMatchToStartOfRange:
{
QDateTime dateTimeStart = mSettings.findLeastClosestDateTime( range.begin() );
range = QgsDateTimeRange( dateTimeStart, dateTimeStart );
break;
}

case QgsRasterDataProviderTemporalCapabilities::FindClosestMatchToEndOfRange:
{
QDateTime dateTimeEnd = mSettings.findLeastClosestDateTime( range.end() );
range = QgsDateTimeRange( dateTimeEnd, dateTimeEnd );
break;
}
}

if ( range.begin() == range.end() )
setQueryItem( query, QStringLiteral( "TIME" ),
range.begin().toString( format ) );
Expand Down

0 comments on commit 88f039e

Please sign in to comment.