Skip to content

Commit

Permalink
Cleanup raster temporal capabilities/layer classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent 3445caf commit 6f92b12
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 263 deletions.
Expand Up @@ -55,50 +55,27 @@ Sets the temporal ``mode``.
.. seealso:: :py:func:`mode`
%End

enum FetchMode
enum IntervalHandlingMethod
{
Earliest,
Latest,
Range
MatchUsingWholeRange,
MatchExactUsingStartOfRange,
MatchExactUsingEndOfRange,
};

FetchMode fetchMode() const;
IntervalHandlingMethod intervalHandlingMethod() const;
%Docstring
Returns the temporal capabilities fetch mode.
Returns the desired method to use when resolving a temporal interval to matching
layers or bands in the data provider.

.. seealso:: :py:func:`setFetchMode`
.. seealso:: :py:func:`setIntervalHandlingMethod`
%End

void setFetchMode( FetchMode mode );
void setIntervalHandlingMethod( IntervalHandlingMethod method );
%Docstring
Sets the temporal properties fetch ``mode``.
Sets the desired ``method`` to use when resolving a temporal interval to matching
layers or bands in the data provider.

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

enum TimeInterval
{
Seconds,
Minutes,
Hours,
Days,
Months,
Years,
None
};

TimeInterval timeInterval() const;
%Docstring
Returns the temporal interval.

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

void setTimeInterval( TimeInterval interval );
%Docstring
Sets the temporal time ``interval``.

.. seealso:: :py:func:`timeInterval`
.. seealso:: :py:func:`intervalHandlingMethod`
%End

void setFixedTemporalRange( const QgsDateTimeRange &range );
Expand Down
Expand Up @@ -50,25 +50,20 @@ Sets the temporal properties ``mode``.
.. seealso:: :py:func:`mode`
%End

enum FetchMode
{
Earliest,
Latest,
Range
};

FetchMode fetchMode() const;
QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod intervalHandlingMethod() const;
%Docstring
Returns the temporal properties fetch mode.
Returns the desired method to use when resolving a temporal interval to matching
layers or bands in the data provider.

.. seealso:: :py:func:`setFetchMode`
.. seealso:: :py:func:`setIntervalHandlingMethod`
%End

void setFetchMode( FetchMode mode );
void setIntervalHandlingMethod( QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod method );
%Docstring
Sets the temporal properties fetch ``mode``.
Sets the desired ``method`` to use when resolving a temporal interval to matching
layers or bands in the data provider.

.. seealso:: :py:func:`fetchMode`
.. seealso:: :py:func:`intervalHandlingMethod`
%End

void setFixedTemporalRange( const QgsDateTimeRange &range );
Expand Down Expand Up @@ -183,14 +178,10 @@ Returns the current active reference datetime range for these temporal propertie
virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context );


TemporalMode indexToMode( int index );
%Docstring
Returns the temporal mode given index
%End

FetchMode indexToFetchMode( int index );
void setDefaultsFromDataProviderTemporalCapabilities( QgsRasterDataProviderTemporalCapabilities *capabilities );
%Docstring
Returns the temporal fetch mode given index
Sets the layers temporal settings to appropriate defaults based on
a provider's temporal ``capabilities``.
%End

};
Expand Down
Expand Up @@ -24,7 +24,7 @@ A widget for configuring the temporal properties for a raster layer.
%End
public:

QgsRasterLayerTemporalPropertiesWidget( QWidget *parent = 0, QgsMapLayer *layer = 0 );
QgsRasterLayerTemporalPropertiesWidget( QWidget *parent = 0, QgsRasterLayer *layer = 0 );
%Docstring
Constructor for QgsRasterLayerTemporalPropertiesWidget.
%End
Expand Down
16 changes: 2 additions & 14 deletions src/core/raster/qgsrasterdataprovidertemporalcapabilities.cpp
Expand Up @@ -102,26 +102,14 @@ void QgsRasterDataProviderTemporalCapabilities::setMode( TemporalMode mode )
mMode = mode;
}

QgsRasterDataProviderTemporalCapabilities::FetchMode QgsRasterDataProviderTemporalCapabilities::fetchMode() const
QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod QgsRasterDataProviderTemporalCapabilities::intervalHandlingMethod() const
{
return mFetchMode;
}

void QgsRasterDataProviderTemporalCapabilities::setFetchMode( FetchMode mode )
void QgsRasterDataProviderTemporalCapabilities::setIntervalHandlingMethod( IntervalHandlingMethod mode )
{
if ( mFetchMode == mode )
return;
mFetchMode = mode;
}

QgsRasterDataProviderTemporalCapabilities::TimeInterval QgsRasterDataProviderTemporalCapabilities::timeInterval() const
{
return mTimeInteval;
}

void QgsRasterDataProviderTemporalCapabilities::setTimeInterval( TimeInterval interval )
{
if ( mTimeInteval == interval )
return;
mTimeInteval = interval;
}
59 changes: 16 additions & 43 deletions src/core/raster/qgsrasterdataprovidertemporalcapabilities.h
Expand Up @@ -71,55 +71,31 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv
void setMode( TemporalMode mode );

/**
* Mode to used to fetch the data from provider. This is applicable for wms based layers.
*
* Method to use when resolving a temporal range to a data provider layer or band.
**/
enum FetchMode
enum IntervalHandlingMethod
{
Earliest = 0, //!< Use the start datetime in the temporal range.
Latest = 1, //!< Use the end datetime in the temporal range.
Range = 2 //!< Use the datetimes in temporal range as range.
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
};
// TODO -- add other methods, like "FindClosestMatchToStartOfRange", "FindClosestMatchToEndOfRange", etc

/**
* Returns the temporal capabilities fetch mode.
* Returns the desired method to use when resolving a temporal interval to matching
* layers or bands in the data provider.
*
*\see setFetchMode()
*\see setIntervalHandlingMethod()
**/
FetchMode fetchMode() const;
IntervalHandlingMethod intervalHandlingMethod() const;

/**
* Sets the temporal properties fetch \a mode.
* Sets the desired \a method to use when resolving a temporal interval to matching
* layers or bands in the data provider.
*
*\see fetchMode()
*\see intervalHandlingMethod()
**/
void setFetchMode( FetchMode mode );

//! Stores the capabilities time interval duration in the temporal ranges.
enum TimeInterval
{
Seconds = 0, //! For seconds
Minutes = 1, //! For minutes
Hours = 2, //! For hours
Days = 3, //! For days
Months = 4, //! For months
Years = 5, //! For years
None = 6 //! if there is no time interval
};

/**
* Returns the temporal interval.
*
*\see setTimeInterval()
**/
TimeInterval timeInterval() const;

/**
* Sets the temporal time \a interval.
*
*\see timeInterval()
**/
void setTimeInterval( TimeInterval interval );
void setIntervalHandlingMethod( IntervalHandlingMethod method );

/**
* Sets the fixed datetime \a range for the temporal properties.
Expand Down Expand Up @@ -259,15 +235,12 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv
//! If reference range has been enabled to be used in these properties
bool mReferenceEnable = false;

//! Data fetch mode.
FetchMode mFetchMode = Earliest;
//! Interval handling method
IntervalHandlingMethod mFetchMode = MatchUsingWholeRange;

//! Temporal capabilities mode.
TemporalMode mMode = ModeTemporalRangeFromDataProvider;

//! Member for time interval.
TimeInterval mTimeInteval = None;

};

#endif // QGSRASTERDATAPROVIDERTEMPORALCAPABILITIES_H
39 changes: 2 additions & 37 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -866,12 +866,10 @@ void QgsRasterLayer::setDataSource( const QString &dataSource, const QString &ba

setDataProvider( provider, options );

if ( mDataProvider )
setDefaultsFromDataProviderTemporalCapabilities(
mDataProvider->temporalCapabilities() );

if ( mValid )
{
mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );

// load default style
bool defaultLoadedFlag = false;
bool restoredStyle = false;
Expand Down Expand Up @@ -962,39 +960,6 @@ QgsRasterLayerTemporalProperties *QgsRasterLayer::temporalProperties()
return mTemporalProperties;
}

void QgsRasterLayer::setDefaultsFromDataProviderTemporalCapabilities(
QgsRasterDataProviderTemporalCapabilities *temporalCapabilities )
{

mTemporalProperties->setFixedTemporalRange( temporalCapabilities->fixedTemporalRange() );
mTemporalProperties->setFixedReferenceTemporalRange( temporalCapabilities->fixedReferenceTemporalRange() );
switch ( temporalCapabilities->mode() )
{
case QgsRasterDataProviderTemporalCapabilities::ModeTemporalRangeFromDataProvider:
mTemporalProperties->setMode( QgsRasterLayerTemporalProperties::ModeTemporalRangeFromDataProvider );
break;

case QgsRasterDataProviderTemporalCapabilities::ModeFixedTemporalRange:
mTemporalProperties->setMode( QgsRasterLayerTemporalProperties::ModeFixedTemporalRange );
break;
}

switch ( temporalCapabilities->fetchMode() )
{
case QgsRasterDataProviderTemporalCapabilities::Earliest:
mTemporalProperties->setFetchMode( QgsRasterLayerTemporalProperties::Earliest );
break;

case QgsRasterDataProviderTemporalCapabilities::Latest:
mTemporalProperties->setFetchMode( QgsRasterLayerTemporalProperties::Latest );
break;

case QgsRasterDataProviderTemporalCapabilities::Range:
mTemporalProperties->setFetchMode( QgsRasterLayerTemporalProperties::Range );
break;
}
}

void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, QgsRasterMinMaxOrigin::Limits limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag )
{
setContrastEnhancement( algorithm,
Expand Down
7 changes: 0 additions & 7 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -502,13 +502,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
bool generateLookupTableFlag,
QgsRasterRenderer *rasterRenderer );

/**
* Sets the defaults capabilities from the provider temporal capabilities
* into layer's temporal properties.
*/
void setDefaultsFromDataProviderTemporalCapabilities(
QgsRasterDataProviderTemporalCapabilities *temporalCapabilities );

//! Refresh renderer
void refreshRenderer( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent );

Expand Down
17 changes: 1 addition & 16 deletions src/core/raster/qgsrasterlayerrenderer.cpp
Expand Up @@ -241,22 +241,7 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
{
mPipe->provider()->temporalCapabilities()->setRequestedTemporalRange( rendererContext.temporalRange() );
mPipe->provider()->temporalCapabilities()->setRequestedReferenceTemporalRange( layer->temporalProperties()->referenceTemporalRange() );

switch ( layer->temporalProperties()->fetchMode() )
{
case QgsRasterLayerTemporalProperties::Earliest:
mPipe->provider()->temporalCapabilities()->setFetchMode(
QgsRasterDataProviderTemporalCapabilities::Earliest );
break;
case QgsRasterLayerTemporalProperties::Latest:
mPipe->provider()->temporalCapabilities()->setFetchMode(
QgsRasterDataProviderTemporalCapabilities::Latest );
break;
case QgsRasterLayerTemporalProperties::Range:
mPipe->provider()->temporalCapabilities()->setFetchMode(
QgsRasterDataProviderTemporalCapabilities::Range );
break;
}
mPipe->provider()->temporalCapabilities()->setIntervalHandlingMethod( layer->temporalProperties()->intervalHandlingMethod() );
}
break;
}
Expand Down

0 comments on commit 6f92b12

Please sign in to comment.