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
%End
int temporalRepresentationBandNumber() const;
int bandNumber() const;
%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::
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
%End
void setTemporalRepresentationBandNumber( int number );
void setBandNumber( int number );
%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::
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
%End
@ -196,9 +196,9 @@ from the layer.
.. versionadded:: 3.38
%End
double temporalRepresentationScale() const;
QgsInterval temporalRepresentationScale() const;
%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.
.. note::
@ -207,16 +207,12 @@ values from the layer.
.. seealso:: :py:func:`setTemporalRepresentationScale`
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. versionadded:: 3.38
%End
void setTemporalRepresentationScale( double scale );
void setTemporalRepresentationScale( QgsInterval scale );
%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.
.. note::
@ -225,44 +221,6 @@ values from the layer.
.. 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
%End

View File

@ -142,28 +142,28 @@ Returns a filtered list of bands which match the specified ``range``.
.. versionadded:: 3.38
%End
int temporalRepresentationBandNumber() const;
int bandNumber() const;
%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::
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
%End
void setTemporalRepresentationBandNumber( int number );
void setBandNumber( int number );
%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::
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
%End
@ -196,9 +196,9 @@ from the layer.
.. versionadded:: 3.38
%End
double temporalRepresentationScale() const;
QgsInterval temporalRepresentationScale() const;
%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.
.. note::
@ -207,16 +207,12 @@ values from the layer.
.. seealso:: :py:func:`setTemporalRepresentationScale`
.. seealso:: :py:func:`temporalRepresentationScaleUnit`
.. seealso:: :py:func:`setTemporalRepresentationScaleUnit`
.. versionadded:: 3.38
%End
void setTemporalRepresentationScale( double scale );
void setTemporalRepresentationScale( QgsInterval scale );
%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.
.. note::
@ -225,44 +221,6 @@ values from the layer.
.. 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
%End

View File

@ -35,6 +35,7 @@
#include "qgsapplication.h"
#include "qgsrastertransparency.h"
#include "qgsrasterlayerutils.h"
#include "qgsinterval.h"
#include "qgsunittypes.h"
#include <QElapsedTimer>
@ -303,7 +304,7 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
break;
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
std::unique_ptr< QgsRasterTransparency > transparency;
@ -314,8 +315,9 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
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 double adjustedUpper = static_cast< double >( temporalProperties->temporalRepresentationOffset().msecsTo( rendererContext.temporalRange().end() ) ) * QgsUnitTypes::fromUnitToUnitFactor( Qgis::TemporalUnit::Milliseconds, temporalProperties->temporalRepresentationScaleUnit() ) / temporalProperties->temporalRepresentationScale();
const QgsInterval scale = 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( adjustedUpper, std::numeric_limits<double>::max(), 0, !rendererContext.zRange().includeUpper(), true ) );

View File

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

View File

@ -22,6 +22,7 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgis.h"
#include "qgsinterval.h"
#include "qgsrange.h"
#include "qgsmaplayertemporalproperties.h"
@ -145,22 +146,22 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP
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.
* \see setTemporalRepresentationBandNumber()
* \see setBandNumber()
* \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.
* \see temporalRepresentationBandNumber()
* \see bandNumber()
* \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
@ -183,50 +184,24 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP
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.
*
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see setTemporalRepresentationScale()
* \see temporalRepresentationScaleUnit()
* \see setTemporalRepresentationScaleUnit()
* \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.
*
* \note This is only considered when mode() is Qgis::RasterTemporalMode::RepresentsTemporalValues.
* \see temporalRepresentationScale()
* \see temporalRepresentationScaleUnit()
* \see setTemporalRepresentationScaleUnit()
* \since QGIS 3.38
*/
void setTemporalRepresentationScale( double 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 );
void setTemporalRepresentationScale( QgsInterval scale );
QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) override;
@ -247,10 +222,10 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP
QMap< int, QgsDateTimeRange > mRangePerBand;
int mTemporalRepresentationBandNumber = 1;
int mBandNumber = 1;
QDateTime mTemporalRepresentationOffset;
double mTemporalRepresentationScale = 1.0;
Qgis::TemporalUnit mTemporalRepresentationScaleUnit = Qgis::TemporalUnit::Days;
QgsInterval mTemporalRepresentationScale;
};
#endif // QGSRASTERLAYERTEMPORALPROPERTIES_H

View File

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

View File

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

View File

@ -21,6 +21,7 @@ from qgis.core import (
Qgis,
QgsCoordinateReferenceSystem,
QgsGeometry,
QgsInterval,
QgsMapClippingRegion,
QgsMapSettings,
QgsRasterLayer,
@ -517,6 +518,57 @@ class TestQgsRasterLayerRenderer(QgisTestCase):
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__':
unittest.main()

View File

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