Skip to content
Permalink
Browse files

Add "allAvailableTemporalRanges" getter/setter to QgsRasterDataProvid…

…erTemporalCapabilities

So that we can store and retrieve a list of all available temporal
ranges for a raster data provider when that range of dates is
non-contiguous
  • Loading branch information
nyalldawson committed Mar 24, 2021
1 parent 4fe99d8 commit 894283b994cb577508f122e183498dc1a378a16b
@@ -60,16 +60,44 @@ layers or bands in the data provider.

void setAvailableTemporalRange( const QgsDateTimeRange &range );
%Docstring
Sets the datetime ``range`` extent from which temporal data is available from the provider.
Sets the overall datetime ``range`` extent from which temporal data is available from the provider.

.. seealso:: :py:func:`availableTemporalRange`
%End

const QgsDateTimeRange &availableTemporalRange() const;
%Docstring
Returns the datetime range extent from which temporal data is available from the provider.
Returns the overall datetime range extent from which temporal data is available from the provider.

.. seealso:: :py:func:`setAvailableTemporalRange`
%End

void setAllAvailableTemporalRanges( const QList< QgsDateTimeRange > &ranges );
%Docstring
Sets a list of all valid datetime ``ranges`` for which temporal data is available from the provider.

As opposed to :py:func:`~QgsRasterDataProviderTemporalCapabilities.setAvailableTemporalRange`, this method is useful when a provider
contains a set of non-contiguous datetime ranges.

.. seealso:: :py:func:`allAvailableTemporalRanges`

.. seealso:: :py:func:`setAvailableTemporalRange`

.. versionadded:: 3.20
%End

QList< QgsDateTimeRange > allAvailableTemporalRanges() const;
%Docstring
Returns a list of all valid datetime ranges for which temporal data is available from the provider.

As opposed to :py:func:`~QgsRasterDataProviderTemporalCapabilities.availableTemporalRange`, this method is useful when a provider
contains a set of non-contiguous datetime ranges.

.. seealso:: :py:func:`setAllAvailableTemporalRanges`

.. seealso:: :py:func:`availableTemporalRange`

.. versionadded:: 3.20
%End

void setAvailableReferenceTemporalRange( const QgsDateTimeRange &range );
@@ -35,6 +35,16 @@ const QgsDateTimeRange &QgsRasterDataProviderTemporalCapabilities::availableTemp
return mAvailableTemporalRange;
}

void QgsRasterDataProviderTemporalCapabilities::setAllAvailableTemporalRanges( const QList<QgsDateTimeRange> &ranges )
{
mAllAvailableTemporalRanges = ranges;
}

QList<QgsDateTimeRange> QgsRasterDataProviderTemporalCapabilities::allAvailableTemporalRanges() const
{
return mAllAvailableTemporalRanges;
}

void QgsRasterDataProviderTemporalCapabilities::setAvailableReferenceTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( !hasTemporalCapabilities() )
@@ -75,19 +75,43 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv
void setIntervalHandlingMethod( IntervalHandlingMethod method );

/**
* Sets the datetime \a range extent from which temporal data is available from the provider.
* Sets the overall datetime \a range extent from which temporal data is available from the provider.
*
* \see availableTemporalRange()
*/
void setAvailableTemporalRange( const QgsDateTimeRange &range );

/**
* Returns the datetime range extent from which temporal data is available from the provider.
* Returns the overall datetime range extent from which temporal data is available from the provider.
*
* \see setAvailableTemporalRange()
*/
const QgsDateTimeRange &availableTemporalRange() const;

/**
* Sets a list of all valid datetime \a ranges for which temporal data is available from the provider.
*
* As opposed to setAvailableTemporalRange(), this method is useful when a provider
* contains a set of non-contiguous datetime ranges.
*
* \see allAvailableTemporalRanges()
* \see setAvailableTemporalRange()
* \since QGIS 3.20
*/
void setAllAvailableTemporalRanges( const QList< QgsDateTimeRange > &ranges );

/**
* Returns a list of all valid datetime ranges for which temporal data is available from the provider.
*
* As opposed to availableTemporalRange(), this method is useful when a provider
* contains a set of non-contiguous datetime ranges.
*
* \see setAllAvailableTemporalRanges()
* \see availableTemporalRange()
* \since QGIS 3.20
*/
QList< QgsDateTimeRange > allAvailableTemporalRanges() const;

/**
* Sets the available reference datetime \a range. This is to be used for
* bi-temporal based data. Where data can have both nominal and reference times.
@@ -134,6 +158,12 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv
*/
QgsDateTimeRange mAvailableTemporalRange;

/**
* A list of all valid temporal ranges for the provider. Used when a provider
* has a non-contiguous set of available temporal ranges.
*/
QList< QgsDateTimeRange > mAllAvailableTemporalRanges;

//! Represents the requested temporal range.
QgsDateTimeRange mRequestedRange;

@@ -88,7 +88,7 @@ bool QgsWmsSettings::parseUri( const QString &uriString )
mTemporalExtent = uri.param( QStringLiteral( "timeDimensionExtent" ) );
mTimeDimensionExtent = parseTemporalExtent( mTemporalExtent );

if ( mTimeDimensionExtent.datesResolutionList.constFirst().dates.dateTimes.size() > 0 )
if ( !mTimeDimensionExtent.datesResolutionList.constFirst().dates.dateTimes.empty() )
{
QDateTime begin = mTimeDimensionExtent.datesResolutionList.constFirst().dates.dateTimes.first();
QDateTime end = mTimeDimensionExtent.datesResolutionList.constLast().dates.dateTimes.last();
@@ -98,6 +98,18 @@ bool QgsWmsSettings::parseUri( const QString &uriString )
else
mFixedRange = QgsDateTimeRange();

mAllRanges.clear();
mAllRanges.reserve( mTimeDimensionExtent.datesResolutionList.size() );
for ( const QgsWmstExtentPair &extent : std::as_const( mTimeDimensionExtent.datesResolutionList ) )
{
if ( extent.dates.dateTimes.empty() )
continue;

const QDateTime begin = extent.dates.dateTimes.first();
const QDateTime end = extent.dates.dateTimes.last();
mAllRanges.append( QgsDateTimeRange( begin, end ) );
}

if ( uri.param( QStringLiteral( "referenceTimeDimensionExtent" ) ) != QString() )
{
QString referenceExtent = uri.param( QStringLiteral( "referenceTimeDimensionExtent" ) );
@@ -884,6 +884,9 @@ class QgsWmsSettings
//! Fixed temporal range for the data provider
QgsDateTimeRange mFixedRange;

//! All available temporal ranges
QList< QgsDateTimeRange > mAllRanges;

//! Fixed reference temporal range for the data provider
QgsDateTimeRange mFixedReferenceRange;

@@ -172,6 +172,8 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri, const ProviderOptions &optio
Q_ASSERT_X( temporalCapabilities(), "QgsWmsProvider::QgsWmsProvider()", "Data provider temporal capabilities object does not exist" );
temporalCapabilities()->setHasTemporalCapabilities( true );
temporalCapabilities()->setAvailableTemporalRange( mSettings.mFixedRange );
temporalCapabilities()->setAllAvailableTemporalRanges( mSettings.mAllRanges );

temporalCapabilities()->setIntervalHandlingMethod(
QgsRasterDataProviderTemporalCapabilities::MatchExactUsingStartOfRange );

0 comments on commit 894283b

Please sign in to comment.