Address review

This commit is contained in:
Mathieu Pellerin 2024-04-06 10:41:37 +07:00 committed by Nyall Dawson
parent 69b8a2c1ab
commit feabbe722e
11 changed files with 138 additions and 196 deletions

View File

@ -142,28 +142,28 @@ Returns a filtered list of bands which match the specified ``range``.
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
int temporalRepresentationBandNumber() const; int bandNumber() const;
%Docstring %Docstring
Returns the band number from which the temporal values should be taken. Returns the band number from which temporal values should be taken.
.. note:: .. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues. This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`setTemporalRepresentationBandNumber` .. seealso:: :py:func:`setBandNumber`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
void setTemporalRepresentationBandNumber( int number ); void setBandNumber( int number );
%Docstring %Docstring
Sets the band number from which the temporal values should be taken. Sets the band number from which temporal values should be taken.
.. note:: .. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues. This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`temporalRepresentationBandNumber` .. seealso:: :py:func:`bandNumber`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
@ -196,9 +196,9 @@ from the layer.
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
double temporalRepresentationScale() const; QgsInterval temporalRepresentationScale() const;
%Docstring %Docstring
Returns the scale, which is a duration factor which should be applied to individual pixel Returns the scale, which is an interval factor which should be applied to individual pixel
values from the layer. values from the layer.
.. note:: .. note::
@ -207,16 +207,12 @@ values from the layer.
.. seealso:: :py:func:`setTemporalRepresentationScale` .. seealso:: :py:func:`setTemporalRepresentationScale`
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
void setTemporalRepresentationScale( double scale ); void setTemporalRepresentationScale( QgsInterval scale );
%Docstring %Docstring
Sets the scale, which is a duration factor which should be applied to individual pixel Sets the scale, which is an interval factor which should be applied to individual pixel
values from the layer. values from the layer.
.. note:: .. note::
@ -225,44 +221,6 @@ values from the layer.
.. seealso:: :py:func:`temporalRepresentationScale` .. seealso:: :py:func:`temporalRepresentationScale`
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. versionadded:: 3.38
%End
Qgis::TemporalUnit temporalRepresentationScaleUnit() const;
%Docstring
Returns the scale's temporal unit type.
.. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. seealso:: :py:func:`temporalRepresentationScale`
.. seealso:: :py:func:`setTemporalRepresentationScale`
.. versionadded:: 3.38
%End
void setTemporalRepresentationScaleUnit( Qgis::TemporalUnit unit );
%Docstring
Sets the scale's temporal unit type.
.. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`temporalRepresentationScale`
.. seealso:: :py:func:`setTemporalRepresentationScale`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End

View File

@ -142,28 +142,28 @@ Returns a filtered list of bands which match the specified ``range``.
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
int temporalRepresentationBandNumber() const; int bandNumber() const;
%Docstring %Docstring
Returns the band number from which the temporal values should be taken. Returns the band number from which temporal values should be taken.
.. note:: .. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues. This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`setTemporalRepresentationBandNumber` .. seealso:: :py:func:`setBandNumber`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
void setTemporalRepresentationBandNumber( int number ); void setBandNumber( int number );
%Docstring %Docstring
Sets the band number from which the temporal values should be taken. Sets the band number from which temporal values should be taken.
.. note:: .. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues. This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`temporalRepresentationBandNumber` .. seealso:: :py:func:`bandNumber`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
@ -196,9 +196,9 @@ from the layer.
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
double temporalRepresentationScale() const; QgsInterval temporalRepresentationScale() const;
%Docstring %Docstring
Returns the scale, which is a duration factor which should be applied to individual pixel Returns the scale, which is an interval factor which should be applied to individual pixel
values from the layer. values from the layer.
.. note:: .. note::
@ -207,16 +207,12 @@ values from the layer.
.. seealso:: :py:func:`setTemporalRepresentationScale` .. seealso:: :py:func:`setTemporalRepresentationScale`
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End
void setTemporalRepresentationScale( double scale ); void setTemporalRepresentationScale( QgsInterval scale );
%Docstring %Docstring
Sets the scale, which is a duration factor which should be applied to individual pixel Sets the scale, which is an interval factor which should be applied to individual pixel
values from the layer. values from the layer.
.. note:: .. note::
@ -225,44 +221,6 @@ values from the layer.
.. seealso:: :py:func:`temporalRepresentationScale` .. seealso:: :py:func:`temporalRepresentationScale`
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. versionadded:: 3.38
%End
Qgis::TemporalUnit temporalRepresentationScaleUnit() const;
%Docstring
Returns the scale's temporal unit type.
.. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. seealso:: :py:func:`temporalRepresentationScale`
.. seealso:: :py:func:`setTemporalRepresentationScale`
.. versionadded:: 3.38
%End
void setTemporalRepresentationScaleUnit( Qgis::TemporalUnit unit );
%Docstring
Sets the scale's temporal unit type.
.. note::
This is only considered when :py:func:`~QgsRasterLayerTemporalProperties.mode` is :py:class:`Qgis`.RasterTemporalMode.RepresentsTemporalValues.
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`temporalRepresentationScale`
.. seealso:: :py:func:`setTemporalRepresentationScale`
.. versionadded:: 3.38 .. versionadded:: 3.38
%End %End

View File

@ -35,6 +35,7 @@
#include "qgsapplication.h" #include "qgsapplication.h"
#include "qgsrastertransparency.h" #include "qgsrastertransparency.h"
#include "qgsrasterlayerutils.h" #include "qgsrasterlayerutils.h"
#include "qgsinterval.h"
#include "qgsunittypes.h" #include "qgsunittypes.h"
#include <QElapsedTimer> #include <QElapsedTimer>
@ -303,7 +304,7 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
break; break;
case Qgis::RasterTemporalMode::RepresentsTemporalValues: case Qgis::RasterTemporalMode::RepresentsTemporalValues:
if ( mPipe->renderer()->usesBands().contains( temporalProperties->temporalRepresentationBandNumber() ) ) if ( mPipe->renderer()->usesBands().contains( temporalProperties->bandNumber() ) )
{ {
// if layer has elevation settings and we are only rendering a temporal range => we need to filter pixels by temporal values // if layer has elevation settings and we are only rendering a temporal range => we need to filter pixels by temporal values
std::unique_ptr< QgsRasterTransparency > transparency; std::unique_ptr< QgsRasterTransparency > transparency;
@ -314,8 +315,9 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
QVector<QgsRasterTransparency::TransparentSingleValuePixel> transparentPixels = transparency->transparentSingleValuePixelList(); QVector<QgsRasterTransparency::TransparentSingleValuePixel> transparentPixels = transparency->transparentSingleValuePixelList();
const double adjustedLower = static_cast< double >( temporalProperties->temporalRepresentationOffset().msecsTo( rendererContext.temporalRange().begin() ) ) * QgsUnitTypes::fromUnitToUnitFactor( Qgis::TemporalUnit::Milliseconds, temporalProperties->temporalRepresentationScaleUnit() ) / temporalProperties->temporalRepresentationScale(); const QgsInterval scale = temporalProperties->temporalRepresentationScale();
const double adjustedUpper = static_cast< double >( temporalProperties->temporalRepresentationOffset().msecsTo( rendererContext.temporalRange().end() ) ) * QgsUnitTypes::fromUnitToUnitFactor( Qgis::TemporalUnit::Milliseconds, temporalProperties->temporalRepresentationScaleUnit() ) / temporalProperties->temporalRepresentationScale(); const double adjustedLower = static_cast< double >( temporalProperties->temporalRepresentationOffset().msecsTo( rendererContext.temporalRange().begin() ) ) * QgsUnitTypes::fromUnitToUnitFactor( Qgis::TemporalUnit::Milliseconds, scale.originalUnit() ) / scale.originalDuration();
const double adjustedUpper = static_cast< double >( temporalProperties->temporalRepresentationOffset().msecsTo( rendererContext.temporalRange().end() ) ) * QgsUnitTypes::fromUnitToUnitFactor( Qgis::TemporalUnit::Milliseconds, scale.originalUnit() ) / scale.originalDuration();
transparentPixels.append( QgsRasterTransparency::TransparentSingleValuePixel( std::numeric_limits<double>::lowest(), adjustedLower, 0, true, !rendererContext.zRange().includeLower() ) ); transparentPixels.append( QgsRasterTransparency::TransparentSingleValuePixel( std::numeric_limits<double>::lowest(), adjustedLower, 0, true, !rendererContext.zRange().includeLower() ) );
transparentPixels.append( QgsRasterTransparency::TransparentSingleValuePixel( adjustedUpper, std::numeric_limits<double>::max(), 0, !rendererContext.zRange().includeUpper(), true ) ); transparentPixels.append( QgsRasterTransparency::TransparentSingleValuePixel( adjustedUpper, std::numeric_limits<double>::max(), 0, !rendererContext.zRange().includeUpper(), true ) );

View File

@ -22,6 +22,7 @@
QgsRasterLayerTemporalProperties::QgsRasterLayerTemporalProperties( QObject *parent, bool enabled ) QgsRasterLayerTemporalProperties::QgsRasterLayerTemporalProperties( QObject *parent, bool enabled )
: QgsMapLayerTemporalProperties( parent, enabled ) : QgsMapLayerTemporalProperties( parent, enabled )
{ {
mTemporalRepresentationScale.setDays( 1.0 );
} }
bool QgsRasterLayerTemporalProperties::isVisibleInTemporalRange( const QgsDateTimeRange &range ) const bool QgsRasterLayerTemporalProperties::isVisibleInTemporalRange( const QgsDateTimeRange &range ) const
@ -236,7 +237,7 @@ int QgsRasterLayerTemporalProperties::bandForTemporalRange( QgsRasterLayer *, co
} }
case Qgis::RasterTemporalMode::RepresentsTemporalValues: case Qgis::RasterTemporalMode::RepresentsTemporalValues:
return mTemporalRepresentationBandNumber; return mBandNumber;
} }
BUILTIN_UNREACHABLE BUILTIN_UNREACHABLE
} }
@ -274,22 +275,22 @@ QList<int> QgsRasterLayerTemporalProperties::filteredBandsForTemporalRange( QgsR
} }
case Qgis::RasterTemporalMode::RepresentsTemporalValues: case Qgis::RasterTemporalMode::RepresentsTemporalValues:
return QList<int>() << mTemporalRepresentationBandNumber; return QList<int>() << mBandNumber;
} }
BUILTIN_UNREACHABLE BUILTIN_UNREACHABLE
} }
int QgsRasterLayerTemporalProperties::temporalRepresentationBandNumber() const int QgsRasterLayerTemporalProperties::bandNumber() const
{ {
return mTemporalRepresentationBandNumber; return mBandNumber;
} }
void QgsRasterLayerTemporalProperties::setTemporalRepresentationBandNumber( int number ) void QgsRasterLayerTemporalProperties::setBandNumber( int number )
{ {
if ( mTemporalRepresentationBandNumber == number ) if ( mBandNumber == number )
return; return;
mTemporalRepresentationBandNumber = number; mBandNumber = number;
} }
QDateTime QgsRasterLayerTemporalProperties::temporalRepresentationOffset() const QDateTime QgsRasterLayerTemporalProperties::temporalRepresentationOffset() const
@ -305,12 +306,12 @@ void QgsRasterLayerTemporalProperties::setTemporalRepresentationOffset( const QD
mTemporalRepresentationOffset = offset; mTemporalRepresentationOffset = offset;
} }
double QgsRasterLayerTemporalProperties::temporalRepresentationScale() const QgsInterval QgsRasterLayerTemporalProperties::temporalRepresentationScale() const
{ {
return mTemporalRepresentationScale; return mTemporalRepresentationScale;
} }
void QgsRasterLayerTemporalProperties::setTemporalRepresentationScale( double scale ) void QgsRasterLayerTemporalProperties::setTemporalRepresentationScale( QgsInterval scale )
{ {
if ( mTemporalRepresentationScale == scale ) if ( mTemporalRepresentationScale == scale )
return; return;
@ -318,19 +319,6 @@ void QgsRasterLayerTemporalProperties::setTemporalRepresentationScale( double sc
mTemporalRepresentationScale = scale; mTemporalRepresentationScale = scale;
} }
Qgis::TemporalUnit QgsRasterLayerTemporalProperties::temporalRepresentationScaleUnit() const
{
return mTemporalRepresentationScaleUnit;
}
void QgsRasterLayerTemporalProperties::setTemporalRepresentationScaleUnit( Qgis::TemporalUnit unit )
{
if ( mTemporalRepresentationScaleUnit == unit )
return;
mTemporalRepresentationScaleUnit = unit;
}
bool QgsRasterLayerTemporalProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context ) bool QgsRasterLayerTemporalProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
{ {
Q_UNUSED( context ) Q_UNUSED( context )
@ -341,6 +329,7 @@ bool QgsRasterLayerTemporalProperties::readXml( const QDomElement &element, cons
setIsActive( temporalNode.attribute( QStringLiteral( "enabled" ), QStringLiteral( "0" ) ).toInt() ); setIsActive( temporalNode.attribute( QStringLiteral( "enabled" ), QStringLiteral( "0" ) ).toInt() );
mMode = static_cast< Qgis::RasterTemporalMode >( temporalNode.attribute( QStringLiteral( "mode" ), QStringLiteral( "0" ) ). toInt() ); mMode = static_cast< Qgis::RasterTemporalMode >( temporalNode.attribute( QStringLiteral( "mode" ), QStringLiteral( "0" ) ). toInt() );
mBandNumber = temporalNode.attribute( QStringLiteral( "bandNumber" ), QStringLiteral( "1" ) ).toInt();
mIntervalHandlingMethod = static_cast< Qgis::TemporalIntervalMatchMethod >( temporalNode.attribute( QStringLiteral( "fetchMode" ), QStringLiteral( "0" ) ). toInt() ); mIntervalHandlingMethod = static_cast< Qgis::TemporalIntervalMatchMethod >( temporalNode.attribute( QStringLiteral( "fetchMode" ), QStringLiteral( "0" ) ). toInt() );
switch ( mMode ) switch ( mMode )
@ -380,10 +369,9 @@ bool QgsRasterLayerTemporalProperties::readXml( const QDomElement &element, cons
case Qgis::RasterTemporalMode::RepresentsTemporalValues: case Qgis::RasterTemporalMode::RepresentsTemporalValues:
{ {
mTemporalRepresentationBandNumber = temporalNode.attribute( QStringLiteral( "temporalRepresentationBandNumber" ), QStringLiteral( "1" ) ).toInt();
mTemporalRepresentationOffset = QDateTime::fromString( temporalNode.attribute( QStringLiteral( "temporalRepresentationOffset" ) ), Qt::ISODate ); mTemporalRepresentationOffset = QDateTime::fromString( temporalNode.attribute( QStringLiteral( "temporalRepresentationOffset" ) ), Qt::ISODate );
mTemporalRepresentationScale = temporalNode.attribute( QStringLiteral( "temporalRepresentationScale" ), QStringLiteral( "1" ) ).toDouble(); mTemporalRepresentationScale = QgsInterval( temporalNode.attribute( QStringLiteral( "temporalRepresentationScale" ), QStringLiteral( "1" ) ).toDouble(),
mTemporalRepresentationScaleUnit = static_cast< Qgis::TemporalUnit >( temporalNode.attribute( QStringLiteral( "temporalRepresentationScaleUnit" ), QStringLiteral( "4" ) ).toInt() ); static_cast< Qgis::TemporalUnit >( temporalNode.attribute( QStringLiteral( "temporalRepresentationScaleUnit" ), QStringLiteral( "4" ) ).toInt() ) );
break; break;
} }
@ -404,6 +392,7 @@ QDomElement QgsRasterLayerTemporalProperties::writeXml( QDomElement &element, QD
QDomElement temporalElement = document.createElement( QStringLiteral( "temporal" ) ); QDomElement temporalElement = document.createElement( QStringLiteral( "temporal" ) );
temporalElement.setAttribute( QStringLiteral( "enabled" ), isActive() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); temporalElement.setAttribute( QStringLiteral( "enabled" ), isActive() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
temporalElement.setAttribute( QStringLiteral( "mode" ), QString::number( static_cast< int >( mMode ) ) ); temporalElement.setAttribute( QStringLiteral( "mode" ), QString::number( static_cast< int >( mMode ) ) );
temporalElement.setAttribute( QStringLiteral( "bandNumber" ), QString::number( mBandNumber ) );
temporalElement.setAttribute( QStringLiteral( "fetchMode" ), QString::number( static_cast< int >( mIntervalHandlingMethod ) ) ); temporalElement.setAttribute( QStringLiteral( "fetchMode" ), QString::number( static_cast< int >( mIntervalHandlingMethod ) ) );
switch ( mMode ) switch ( mMode )
@ -446,10 +435,9 @@ QDomElement QgsRasterLayerTemporalProperties::writeXml( QDomElement &element, QD
case Qgis::RasterTemporalMode::RepresentsTemporalValues: case Qgis::RasterTemporalMode::RepresentsTemporalValues:
{ {
temporalElement.setAttribute( QStringLiteral( "temporalRepresentationBandNumber" ), QString::number( mTemporalRepresentationBandNumber ) );
temporalElement.setAttribute( QStringLiteral( "temporalRepresentationOffset" ), mTemporalRepresentationOffset.toString( Qt::ISODate ) ); temporalElement.setAttribute( QStringLiteral( "temporalRepresentationOffset" ), mTemporalRepresentationOffset.toString( Qt::ISODate ) );
temporalElement.setAttribute( QStringLiteral( "temporalRepresentationScale" ), QString::number( mTemporalRepresentationScale ) ); temporalElement.setAttribute( QStringLiteral( "temporalRepresentationScale" ), QString::number( mTemporalRepresentationScale.originalDuration() ) );
temporalElement.setAttribute( QStringLiteral( "temporalRepresentationScaleUnit" ), QString::number( static_cast< int >( mTemporalRepresentationScaleUnit ) ) ); temporalElement.setAttribute( QStringLiteral( "temporalRepresentationScaleUnit" ), QString::number( static_cast< int >( mTemporalRepresentationScale.originalUnit() ) ) );
break; break;
} }

View File

@ -22,6 +22,7 @@
#include "qgis_core.h" #include "qgis_core.h"
#include "qgis_sip.h" #include "qgis_sip.h"
#include "qgis.h" #include "qgis.h"
#include "qgsinterval.h"
#include "qgsrange.h" #include "qgsrange.h"
#include "qgsmaplayertemporalproperties.h" #include "qgsmaplayertemporalproperties.h"
@ -145,22 +146,22 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP
QList< int > filteredBandsForTemporalRange( QgsRasterLayer *layer, const QgsDateTimeRange &range ) const; QList< int > filteredBandsForTemporalRange( QgsRasterLayer *layer, const QgsDateTimeRange &range ) const;
/** /**
* Returns the band number from which the temporal values should be taken. * Returns the band number from which temporal values should be taken.
* *
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues. * \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see setTemporalRepresentationBandNumber() * \see setBandNumber()
* \since QGIS 3.38 * \since QGIS 3.38
*/ */
int temporalRepresentationBandNumber() const; int bandNumber() const;
/** /**
* Sets the band number from which the temporal values should be taken. * Sets the band number from which temporal values should be taken.
* *
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues. * \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see temporalRepresentationBandNumber() * \see bandNumber()
* \since QGIS 3.38 * \since QGIS 3.38
*/ */
void setTemporalRepresentationBandNumber( int number ); void setBandNumber( int number );
/** /**
* Returns the temporal offset, which is a fixed datetime which should be added to individual pixel values * Returns the temporal offset, which is a fixed datetime which should be added to individual pixel values
@ -183,50 +184,24 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP
void setTemporalRepresentationOffset( const QDateTime &offset ); void setTemporalRepresentationOffset( const QDateTime &offset );
/** /**
* Returns the scale, which is a duration factor which should be applied to individual pixel * Returns the scale, which is an interval factor which should be applied to individual pixel
* values from the layer. * values from the layer.
* *
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues. * \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see setTemporalRepresentationScale() * \see setTemporalRepresentationScale()
* \see temporalRepresentationScaleUnit()
* \see setTemporalRepresentationScaleUnit()
* \since QGIS 3.38 * \since QGIS 3.38
*/ */
double temporalRepresentationScale() const; QgsInterval temporalRepresentationScale() const;
/** /**
* Sets the scale, which is a duration factor which should be applied to individual pixel * Sets the scale, which is an interval factor which should be applied to individual pixel
* values from the layer. * values from the layer.
* *
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues. * \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see temporalRepresentationScale() * \see temporalRepresentationScale()
* \see temporalRepresentationScaleUnit()
* \see setTemporalRepresentationScaleUnit()
* \since QGIS 3.38 * \since QGIS 3.38
*/ */
void setTemporalRepresentationScale( double scale ); void setTemporalRepresentationScale( QgsInterval scale );
/**
* Returns the scale's temporal unit type.
*
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see setTemporalRepresentationScaleUnit()
* \see temporalRepresentationScale()
* \see setTemporalRepresentationScale()
* \since QGIS 3.38
*/
Qgis::TemporalUnit temporalRepresentationScaleUnit() const;
/**
* Sets the scale's temporal unit type.
*
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see temporalRepresentationScaleUnit()
* \see temporalRepresentationScale()
* \see setTemporalRepresentationScale()
* \since QGIS 3.38
*/
void setTemporalRepresentationScaleUnit( Qgis::TemporalUnit unit );
QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) override; QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) override;
@ -247,10 +222,10 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP
QMap< int, QgsDateTimeRange > mRangePerBand; QMap< int, QgsDateTimeRange > mRangePerBand;
int mTemporalRepresentationBandNumber = 1; int mBandNumber = 1;
QDateTime mTemporalRepresentationOffset; QDateTime mTemporalRepresentationOffset;
double mTemporalRepresentationScale = 1.0; QgsInterval mTemporalRepresentationScale;
Qgis::TemporalUnit mTemporalRepresentationScaleUnit = Qgis::TemporalUnit::Days;
}; };
#endif // QGSRASTERLAYERTEMPORALPROPERTIES_H #endif // QGSRASTERLAYERTEMPORALPROPERTIES_H

View File

@ -72,7 +72,7 @@ int QgsRasterLayerUtils::renderedBandForElevationAndTemporalRange(
case Qgis::RasterTemporalMode::RepresentsTemporalValues: case Qgis::RasterTemporalMode::RepresentsTemporalValues:
{ {
temporalBands << temporalProperties->temporalRepresentationBandNumber(); temporalBands << temporalProperties->bandNumber();
break; break;
} }
} }

View File

@ -115,6 +115,7 @@ void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties()
QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() ); QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
temporalProperties->setMode( mModeComboBox->currentData().value< Qgis::RasterTemporalMode >() ); temporalProperties->setMode( mModeComboBox->currentData().value< Qgis::RasterTemporalMode >() );
temporalProperties->setBandNumber( mBandComboBox->currentBand() );
const QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(), const QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(),
mEndTemporalDateTimeEdit->dateTime() ); mEndTemporalDateTimeEdit->dateTime() );
@ -124,10 +125,8 @@ void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties()
temporalProperties->setTemporalRepresentationOffset( mOffsetDateTimeEdit->dateTime() ); temporalProperties->setTemporalRepresentationOffset( mOffsetDateTimeEdit->dateTime() );
temporalProperties->setTemporalRepresentationScale( mScaleSpinBox->value() ); const QgsInterval scale( mScaleSpinBox->value(), static_cast< Qgis::TemporalUnit >( mScaleUnitComboBox->currentData().toInt() ) );
temporalProperties->setTemporalRepresentationScaleUnit( static_cast< Qgis::TemporalUnit >( mScaleUnitComboBox->currentData().toInt() ) ); temporalProperties->setTemporalRepresentationScale( scale );
temporalProperties->setTemporalRepresentationBandNumber( mBandComboBox->currentBand() );
for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) ) for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
{ {
@ -158,6 +157,9 @@ void QgsRasterLayerTemporalPropertiesWidget::syncToLayer()
break; break;
} }
mBandComboBox->setLayer( mLayer );
mBandComboBox->setBand( temporalProperties->bandNumber() );
mStartTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().begin() ); mStartTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().begin() );
mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() ); mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() );
@ -168,11 +170,8 @@ void QgsRasterLayerTemporalPropertiesWidget::syncToLayer()
mOffsetDateTimeEdit->setDateTime( temporalProperties->temporalRepresentationOffset() ); mOffsetDateTimeEdit->setDateTime( temporalProperties->temporalRepresentationOffset() );
mScaleSpinBox->setValue( temporalProperties->temporalRepresentationScale() ); mScaleSpinBox->setValue( temporalProperties->temporalRepresentationScale().originalDuration() );
mScaleUnitComboBox->setCurrentIndex( mScaleUnitComboBox->findData( static_cast< int >( temporalProperties->temporalRepresentationScaleUnit() ) ) ); mScaleUnitComboBox->setCurrentIndex( mScaleUnitComboBox->findData( static_cast< int >( temporalProperties->temporalRepresentationScale().originalUnit() ) ) );
mBandComboBox->setLayer( mLayer );
mBandComboBox->setBand( temporalProperties->temporalRepresentationBandNumber() );
mTemporalGroupBox->setChecked( temporalProperties->isActive() ); mTemporalGroupBox->setChecked( temporalProperties->isActive() );

View File

@ -21,6 +21,7 @@ from qgis.core import (
Qgis, Qgis,
QgsCoordinateReferenceSystem, QgsCoordinateReferenceSystem,
QgsGeometry, QgsGeometry,
QgsInterval,
QgsMapClippingRegion, QgsMapClippingRegion,
QgsMapSettings, QgsMapSettings,
QgsRasterLayer, QgsRasterLayer,
@ -517,6 +518,57 @@ class TestQgsRasterLayerRenderer(QgisTestCase):
map_settings) map_settings)
) )
def test_render_represents_temporal_values(self):
"""
Test rendering a raster with its temporal properties' mode set
to represents temporal values
"""
raster_layer = QgsRasterLayer(os.path.join(TEST_DATA_DIR, 'scaleoffset.tif'))
self.assertTrue(raster_layer.isValid())
renderer = QgsSingleBandGrayRenderer(raster_layer.dataProvider(), 1)
raster_layer.setRenderer(renderer)
# set layer as temporal enabled
raster_layer.temporalProperties().setIsActive(True)
raster_layer.temporalProperties().setMode(
Qgis.RasterTemporalMode.RepresentsTemporalValues
)
raster_layer.temporalProperties().setBandNumber(1)
raster_layer.temporalProperties().setTemporalRepresentationOffset(QDateTime(QDate(2024, 1, 1), QTime(0, 0, 0)))
raster_layer.temporalProperties().setTemporalRepresentationScale(QgsInterval(1, Qgis.TemporalUnit.Days))
map_settings = QgsMapSettings()
map_settings.setOutputSize(QSize(400, 400))
map_settings.setOutputDpi(96)
map_settings.setDestinationCrs(raster_layer.crs())
map_settings.setExtent(raster_layer.extent())
map_settings.setLayers([raster_layer])
# no filter on map settings
map_settings.setIsTemporal(False)
self.assertTrue(
self.render_map_settings_check(
'No temporal range filter on map settings on represents temporal values mode',
'represents_temporal_values_no_filter',
map_settings)
)
# map settings matches part of the overall range
map_settings.setIsTemporal(True)
map_settings.setTemporalRange(QgsDateTimeRange(
QDateTime(QDate(2024, 1, 1),
QTime(0, 0, 0)),
QDateTime(QDate(2024, 1, 5),
QTime(23, 59, 59))
))
self.assertTrue(
self.render_map_settings_check(
'Temporal range filter on map settings on represents temporal values mode',
'represents_temporal_values_filter',
map_settings)
)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -16,6 +16,7 @@ from qgis.PyQt.QtCore import (
from qgis.PyQt.QtXml import QDomDocument from qgis.PyQt.QtXml import QDomDocument
from qgis.core import ( from qgis.core import (
Qgis, Qgis,
QgsInterval,
QgsRasterLayerTemporalProperties, QgsRasterLayerTemporalProperties,
QgsReadWriteContext, QgsReadWriteContext,
QgsDateTimeRange QgsDateTimeRange
@ -281,23 +282,33 @@ class TestQgsRasterLayerTemporalProperties(QgisTestCase):
props.setMode(Qgis.RasterTemporalMode.RepresentsTemporalValues) props.setMode(Qgis.RasterTemporalMode.RepresentsTemporalValues)
self.assertEqual(props.mode(), self.assertEqual(props.mode(),
Qgis.RasterTemporalMode.RepresentsTemporalValues) Qgis.RasterTemporalMode.RepresentsTemporalValues)
self.assertEqual(props.temporalRepresentationScale(), 1) self.assertEqual(props.bandNumber(), 1)
self.assertEqual(props.temporalRepresentationScaleUnit(), Qgis.TemporalUnit.Days) self.assertEqual(props.temporalRepresentationScale(), QgsInterval(1, Qgis.TemporalUnit.Days))
self.assertEqual(props.temporalRepresentationOffset(), QDateTime()) self.assertEqual(props.temporalRepresentationOffset(), QDateTime())
self.assertEqual(props.temporalRepresentationBandNumber(), 1)
self.assertFalse(props.isActive()) self.assertFalse(props.isActive())
props.setTemporalRepresentationScale(2.5) props.setBandNumber(2)
props.setTemporalRepresentationScaleUnit(Qgis.TemporalUnit.Weeks) props.setTemporalRepresentationScale(QgsInterval(2.5, Qgis.TemporalUnit.Weeks))
props.setTemporalRepresentationOffset(QDateTime(QDate(2024, 1, 1), QTime(0, 0, 0))) props.setTemporalRepresentationOffset(QDateTime(QDate(2024, 1, 1), QTime(0, 0, 0)))
props.setTemporalRepresentationBandNumber(2)
props.setIsActive(True) props.setIsActive(True)
self.assertEqual(props.temporalRepresentationScale(), 2.5) self.assertEqual(props.bandNumber(), 2)
self.assertEqual(props.temporalRepresentationScaleUnit(), Qgis.TemporalUnit.Weeks) self.assertEqual(props.temporalRepresentationScale(), QgsInterval(2.5, Qgis.TemporalUnit.Weeks))
self.assertEqual(props.temporalRepresentationOffset(), QDateTime(QDate(2024, 1, 1), QTime(0, 0, 0))) self.assertEqual(props.temporalRepresentationOffset(), QDateTime(QDate(2024, 1, 1), QTime(0, 0, 0)))
self.assertEqual(props.temporalRepresentationBandNumber(), 2)
self.assertTrue(props.isActive()) self.assertTrue(props.isActive())
self.assertEqual(props.bandForTemporalRange(None, QgsDateTimeRange(
QDateTime(QDate(2023, 5, 3),
QTime(12, 13, 14)),
QDateTime(QDate(2023, 5, 4),
QTime(12, 13, 14))
)), 2)
self.assertEqual(props.filteredBandsForTemporalRange(None, QgsDateTimeRange(
QDateTime(QDate(2023, 5, 3),
QTime(12, 13, 14)),
QDateTime(QDate(2023, 5, 4),
QTime(12, 13, 14))
)), [2])
doc = QDomDocument("testdoc") doc = QDomDocument("testdoc")
elem = doc.createElement('test') elem = doc.createElement('test')
props.writeXml(elem, doc, QgsReadWriteContext()) props.writeXml(elem, doc, QgsReadWriteContext())
@ -306,10 +317,9 @@ class TestQgsRasterLayerTemporalProperties(QgisTestCase):
props2.readXml(elem, QgsReadWriteContext()) props2.readXml(elem, QgsReadWriteContext())
self.assertEqual(props2.mode(), self.assertEqual(props2.mode(),
Qgis.RasterTemporalMode.RepresentsTemporalValues) Qgis.RasterTemporalMode.RepresentsTemporalValues)
self.assertEqual(props2.temporalRepresentationScale(), 2.5) self.assertEqual(props.bandNumber(), 2)
self.assertEqual(props2.temporalRepresentationScaleUnit(), Qgis.TemporalUnit.Weeks) self.assertEqual(props2.temporalRepresentationScale(), QgsInterval(2.5, Qgis.TemporalUnit.Weeks))
self.assertEqual(props2.temporalRepresentationOffset(), QDateTime(QDate(2024, 1, 1), QTime(0, 0, 0))) self.assertEqual(props2.temporalRepresentationOffset(), QDateTime(QDate(2024, 1, 1), QTime(0, 0, 0)))
self.assertEqual(props2.temporalRepresentationBandNumber(), 2)
self.assertTrue(props2.isActive()) self.assertTrue(props2.isActive())