39 for (
auto it = mRangePerBand.constBegin(); it != mRangePerBand.constEnd(); ++it )
41 if ( it.value().overlaps( range ) )
56 QgsRasterLayer *rasterLayer = qobject_cast< QgsRasterLayer *>( layer );
72 bool includeBeginning =
true;
73 bool includeEnd =
true;
74 for (
auto it = mRangePerBand.constBegin(); it != mRangePerBand.constEnd(); ++it )
76 if ( it.value().begin() < begin || !begin.isValid() )
78 begin = it.value().begin();
79 includeBeginning = it.value().includeBeginning();
81 else if ( !includeBeginning && it.value().begin() == begin && it.value().includeBeginning() )
83 includeBeginning =
true;
85 if ( it.value().end() > end || !end.isValid() )
87 end = it.value().end();
88 includeEnd = it.value().includeEnd();
90 else if ( !includeEnd && it.value().end() == end && it.value().includeEnd() )
107 QgsRasterLayer *rasterLayer = qobject_cast< QgsRasterLayer *>( layer );
112 return { mFixedRange };
116 QList<QgsDateTimeRange> results;
117 results.reserve( mRangePerBand.size() );
118 for (
auto it = mRangePerBand.constBegin(); it != mRangePerBand.constEnd(); ++it )
120 results.append( it.value() );
170 return mIntervalHandlingMethod;
175 if ( mIntervalHandlingMethod == method )
177 mIntervalHandlingMethod = method;
192 return mRangePerBand;
197 if ( mRangePerBand == ranges )
200 mRangePerBand = ranges;
216 int currentMatchingBand = -1;
218 for (
auto it = mRangePerBand.constBegin(); it != mRangePerBand.constEnd(); ++it )
220 if ( it.value().overlaps( range ) )
223 || ( it.value().includeEnd() && it.value().end() >= currentMatchingRange.
end() )
224 || ( !currentMatchingRange.
includeEnd() && it.value().end() >= currentMatchingRange.
end() ) )
226 currentMatchingBand = it.key();
227 currentMatchingRange = it.value();
231 return currentMatchingBand;
242 const QDomElement temporalNode = element.firstChildElement( QStringLiteral(
"temporal" ) );
244 setIsActive( temporalNode.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ).toInt() );
246 mMode =
static_cast< Qgis::RasterTemporalMode >( temporalNode.attribute( QStringLiteral(
"mode" ), QStringLiteral(
"0" ) ). toInt() );
247 mIntervalHandlingMethod =
static_cast< Qgis::TemporalIntervalMatchMethod >( temporalNode.attribute( QStringLiteral(
"fetchMode" ), QStringLiteral(
"0" ) ). toInt() );
253 const QDomNode rangeElement = temporalNode.namedItem( QStringLiteral(
"fixedRange" ) );
255 const QDomNode begin = rangeElement.namedItem( QStringLiteral(
"start" ) );
256 const QDomNode end = rangeElement.namedItem( QStringLiteral(
"end" ) );
258 const QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
259 const QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );
268 mRangePerBand.clear();
270 const QDomNodeList ranges = temporalNode.firstChildElement( QStringLiteral(
"ranges" ) ).childNodes();
271 for (
int i = 0; i < ranges.size(); ++i )
273 const QDomElement rangeElement = ranges.at( i ).toElement();
274 const int band = rangeElement.attribute( QStringLiteral(
"band" ) ).toInt();
275 const QDateTime begin = QDateTime::fromString( rangeElement.attribute( QStringLiteral(
"begin" ) ), Qt::ISODate );
276 const QDateTime end = QDateTime::fromString( rangeElement.attribute( QStringLiteral(
"end" ) ), Qt::ISODate );
277 const bool includeBeginning = rangeElement.attribute( QStringLiteral(
"includeBeginning" ) ).toInt();
278 const bool includeEnd = rangeElement.attribute( QStringLiteral(
"includeEnd" ) ).toInt();
279 mRangePerBand.insert( band,
QgsDateTimeRange( begin, end, includeBeginning, includeEnd ) );
295 if ( element.isNull() )
296 return QDomElement();
298 QDomElement temporalElement = document.createElement( QStringLiteral(
"temporal" ) );
299 temporalElement.setAttribute( QStringLiteral(
"enabled" ),
isActive() ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
300 temporalElement.setAttribute( QStringLiteral(
"mode" ), QString::number(
static_cast< int >( mMode ) ) );
301 temporalElement.setAttribute( QStringLiteral(
"fetchMode" ), QString::number(
static_cast< int >( mIntervalHandlingMethod ) ) );
308 QDomElement rangeElement = document.createElement( QStringLiteral(
"fixedRange" ) );
310 QDomElement startElement = document.createElement( QStringLiteral(
"start" ) );
311 QDomElement endElement = document.createElement( QStringLiteral(
"end" ) );
313 const QDomText startText = document.createTextNode( mFixedRange.
begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
314 const QDomText endText = document.createTextNode( mFixedRange.
end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
315 startElement.appendChild( startText );
316 endElement.appendChild( endText );
317 rangeElement.appendChild( startElement );
318 rangeElement.appendChild( endElement );
320 temporalElement.appendChild( rangeElement );
326 QDomElement ranges = document.createElement( QStringLiteral(
"ranges" ) );
327 for (
auto it = mRangePerBand.constBegin(); it != mRangePerBand.constEnd(); ++it )
329 QDomElement range = document.createElement( QStringLiteral(
"range" ) );
330 range.setAttribute( QStringLiteral(
"band" ), it.key() );
331 range.setAttribute( QStringLiteral(
"begin" ), it.value().begin().toString( Qt::ISODate ) );
332 range.setAttribute( QStringLiteral(
"end" ), it.value().end().toString( Qt::ISODate ) );
333 range.setAttribute( QStringLiteral(
"includeBeginning" ), it.value().includeBeginning() ?
"1" :
"0" );
334 range.setAttribute( QStringLiteral(
"includeEnd" ), it.value().includeEnd() ?
"1" :
"0" );
335 ranges.appendChild( range );
337 temporalElement.appendChild( ranges );
346 element.appendChild( temporalElement );
355 setIsActive( rasterCaps->hasTemporalCapabilities() );
358 if ( rasterCaps->hasTemporalCapabilities() )
363 mIntervalHandlingMethod = rasterCaps->intervalHandlingMethod();
TemporalIntervalMatchMethod
Method to use when resolving a temporal range to a data provider layer or band.
RasterTemporalMode
Raster layer temporal modes.
@ RedrawLayerOnly
Redraw the layer when temporal range changes, but don't apply any filtering. Useful when raster symbo...
@ FixedRangePerBand
Layer has a fixed temporal range per band (since QGIS 3.38)
@ TemporalRangeFromDataProvider
Mode when raster layer delegates temporal range handling to the dataprovider.
@ FixedTemporalRange
Mode when temporal properties have fixed start and end datetimes.
Base class for handling properties relating to a data provider's temporal capabilities.
Base class for storage of map layer temporal properties.
Base class for all map layer types.
Implementation of data provider temporal properties for QgsRasterDataProviders.
QList< QgsDateTimeRange > allAvailableTemporalRanges() const
Returns a list of all valid datetime ranges for which temporal data is available from the provider.
const QgsDateTimeRange & availableTemporalRange() const
Returns the overall datetime range extent from which temporal data is available from the provider.
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities) override
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
bool isVisibleInTemporalRange(const QgsDateTimeRange &range) const override
Returns true if the layer should be visible and rendered for the specified time range.
QgsTemporalProperty::Flags flags() const override
Returns flags associated to the temporal property.
Qgis::TemporalIntervalMatchMethod intervalHandlingMethod() const
Returns the desired method to use when resolving a temporal interval to matching layers or bands in t...
void setIntervalHandlingMethod(Qgis::TemporalIntervalMatchMethod method)
Sets the desired method to use when resolving a temporal interval to matching layers or bands in the ...
Qgis::RasterTemporalMode mode() const
Returns the temporal properties mode.
int bandForTemporalRange(QgsRasterLayer *layer, const QgsDateTimeRange &range) const
Returns the band corresponding to the specified range.
QList< QgsDateTimeRange > allTemporalRanges(QgsMapLayer *layer) const override
Attempts to calculate the overall list of all temporal extents which are contained in the specified l...
void setMode(Qgis::RasterTemporalMode mode)
Sets the temporal properties mode.
QgsRasterLayerTemporalProperties(QObject *parent=nullptr, bool enabled=false)
Constructor for QgsRasterLayerTemporalProperties, with the specified parent object.
void setFixedTemporalRange(const QgsDateTimeRange &range)
Sets a temporal range to apply to the whole layer.
void setFixedRangePerBand(const QMap< int, QgsDateTimeRange > &ranges)
Sets the fixed temporal range for each band.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads temporal properties from a DOM element previously written by writeXml().
QMap< int, QgsDateTimeRange > fixedRangePerBand() const
Returns the fixed temporal range for each band.
const QgsDateTimeRange & fixedTemporalRange() const
Returns the fixed temporal range for the layer.
QgsDateTimeRange calculateTemporalExtent(QgsMapLayer *layer) const override
Attempts to calculate the overall temporal extent for the specified layer, using the settings defined...
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
The class is used as a container of context for various read/write operations on other objects.
void changed()
Emitted when the temporal properties have changed.
bool isActive() const
Returns true if the temporal property is active.
void setIsActive(bool active)
Sets whether the temporal property is active.
@ FlagDontInvalidateCachedRendersWhenRangeChanges
Any cached rendering will not be invalidated when temporal range context is modified.
T begin() const
Returns the beginning of the range.
T end() const
Returns the upper bound of the range.
bool overlaps(const QgsTemporalRange< T > &other) const
Returns true if this range overlaps another range.
bool includeEnd() const
Returns true if the end is inclusive, or false if the end is exclusive.
bool isInfinite() const
Returns true if the range consists of all possible values.
#define BUILTIN_UNREACHABLE
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.