QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgsvectorlayertemporalproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayertemporalproperties.cpp
3 ---------------
4 begin : May 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include "qgsexpression.h"
22#include "qgsfields.h"
23#include "qgsunittypes.h"
25#include "qgsvectorlayer.h"
26
27#include <QString>
28
29#include "moc_qgsvectorlayertemporalproperties.cpp"
30
31using namespace Qt::StringLiterals;
32
36
56
58{
59 QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
60 if ( !layer )
61 return QgsDateTimeRange();
62
63 switch ( mMode )
64 {
66 return mFixedRange;
67
69 {
70 const int fieldIndex = vectorLayer->fields().lookupField( mStartFieldName );
71 if ( fieldIndex >= 0 )
72 {
73 QVariant minVal;
74 QVariant maxVal;
75 vectorLayer->minimumAndMaximumValue( fieldIndex, minVal, maxVal );
76
77 const QDateTime min = minVal.toDateTime();
78 const QDateTime maxStartTime = maxVal.toDateTime();
79 const QgsInterval eventDuration = QgsInterval( mFixedDuration, mDurationUnit );
80 return QgsDateTimeRange( min, maxStartTime + eventDuration );
81 }
82 break;
83 }
84
86 {
87 const int fieldIndex = vectorLayer->fields().lookupField( mStartFieldName );
88 const int durationFieldIndex = vectorLayer->fields().lookupField( mDurationFieldName );
89 if ( fieldIndex >= 0 && durationFieldIndex >= 0 )
90 {
91 const QDateTime minTime = vectorLayer->minimumValue( fieldIndex ).toDateTime();
92 // no choice here but to loop through all features to calculate max time :(
93
94 QgsFeature f;
95 QgsFeatureIterator it = vectorLayer->getFeatures(
96 QgsFeatureRequest().setFlags( Qgis::FeatureRequestFlag::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() << durationFieldIndex << fieldIndex )
97 );
98 QDateTime maxTime;
99 while ( it.nextFeature( f ) )
100 {
101 const QDateTime start = f.attribute( fieldIndex ).toDateTime();
102 if ( start.isValid() )
103 {
104 const QVariant durationValue = f.attribute( durationFieldIndex );
105 if ( durationValue.isValid() )
106 {
107 const double duration = durationValue.toDouble();
108 const QDateTime end = start.addMSecs( QgsInterval( duration, mDurationUnit ).seconds() * 1000.0 );
109 if ( end.isValid() )
110 maxTime = maxTime.isValid() ? std::max( maxTime, end ) : end;
111 }
112 }
113 }
114 return QgsDateTimeRange( minTime, maxTime );
115 }
116 break;
117 }
118
120 {
121 const int startFieldIndex = vectorLayer->fields().lookupField( mStartFieldName );
122 const int endFieldIndex = vectorLayer->fields().lookupField( mEndFieldName );
123 if ( startFieldIndex >= 0 && endFieldIndex >= 0 )
124 {
125 QVariant startMinVal;
126 QVariant startMaxVal;
127 vectorLayer->minimumAndMaximumValue( startFieldIndex, startMinVal, startMaxVal );
128 QVariant endMinVal;
129 QVariant endMaxVal;
130 vectorLayer->minimumAndMaximumValue( endFieldIndex, endMinVal, endMaxVal );
131
132 return QgsDateTimeRange( std::min( startMinVal.toDateTime(), endMinVal.toDateTime() ), std::max( startMaxVal.toDateTime(), endMaxVal.toDateTime() ) );
133 }
134 else if ( startFieldIndex >= 0 )
135 {
136 QVariant startMinVal;
137 QVariant startMaxVal;
138 vectorLayer->minimumAndMaximumValue( startFieldIndex, startMinVal, startMaxVal );
139 return QgsDateTimeRange( startMinVal.toDateTime(), startMaxVal.toDateTime() );
140 }
141 else if ( endFieldIndex >= 0 )
142 {
143 QVariant endMinVal;
144 QVariant endMaxVal;
145 vectorLayer->minimumAndMaximumValue( endFieldIndex, endMinVal, endMaxVal );
146 return QgsDateTimeRange( endMinVal.toDateTime(), endMaxVal.toDateTime() );
147 }
148 break;
149 }
150
152 {
153 const bool hasStartExpression = !mStartExpression.isEmpty();
154 const bool hasEndExpression = !mEndExpression.isEmpty();
155 if ( !hasStartExpression && !hasEndExpression )
156 return QgsDateTimeRange();
157
158 QDateTime minTime;
159 QDateTime maxTime;
160
161 // no choice here but to loop through all features
162 QgsExpressionContext context;
164
166 if ( hasStartExpression )
167 {
168 startExpression.setExpression( mStartExpression );
169 startExpression.prepare( &context );
170 }
171
173 if ( hasEndExpression )
174 {
175 endExpression.setExpression( mEndExpression );
176 endExpression.prepare( &context );
177 }
178
179 QSet< QString > fields;
180 if ( hasStartExpression )
181 fields.unite( startExpression.referencedColumns() );
182 if ( hasEndExpression )
183 fields.unite( endExpression.referencedColumns() );
184
185 const bool needsGeom = startExpression.needsGeometry() || endExpression.needsGeometry();
186
188 if ( !needsGeom )
190
191 req.setSubsetOfAttributes( fields, vectorLayer->fields() );
192
193 QgsFeature f;
194 QgsFeatureIterator it = vectorLayer->getFeatures( req );
195 while ( it.nextFeature( f ) )
196 {
197 context.setFeature( f );
198 const QDateTime start = hasStartExpression ? startExpression.evaluate( &context ).toDateTime() : QDateTime();
199 const QDateTime end = hasEndExpression ? endExpression.evaluate( &context ).toDateTime() : QDateTime();
200
201 if ( start.isValid() )
202 {
203 minTime = minTime.isValid() ? std::min( minTime, start ) : start;
204 if ( !hasEndExpression )
205 maxTime = maxTime.isValid() ? std::max( maxTime, start ) : start;
206 }
207 if ( end.isValid() )
208 {
209 maxTime = maxTime.isValid() ? std::max( maxTime, end ) : end;
210 if ( !hasStartExpression )
211 minTime = minTime.isValid() ? std::min( minTime, end ) : end;
212 }
213 }
214 return QgsDateTimeRange( minTime, maxTime );
215 }
216
218 break;
219 }
220
221 return QgsDateTimeRange();
222}
223
228
230{
231 if ( mMode == mode )
232 return;
233 mMode = mode;
234}
235
240
242{
243 if ( mLimitMode == limitMode )
244 return;
245 mLimitMode = limitMode;
246}
247
252
254{
255 mFixedRange = range;
256}
257
259{
260 return mFixedRange;
261}
262
263bool QgsVectorLayerTemporalProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
264{
265 Q_UNUSED( context )
266
267 const QDomElement temporalNode = element.firstChildElement( u"temporal"_s );
268
269 setIsActive( temporalNode.attribute( u"enabled"_s, u"0"_s ).toInt() );
270
271 mMode = static_cast< Qgis::VectorTemporalMode >( temporalNode.attribute( u"mode"_s, u"0"_s ).toInt() );
272
273 mLimitMode = static_cast< Qgis::VectorTemporalLimitMode >( temporalNode.attribute( u"limitMode"_s, u"0"_s ).toInt() );
274 mStartFieldName = temporalNode.attribute( u"startField"_s );
275 mEndFieldName = temporalNode.attribute( u"endField"_s );
276 mStartExpression = temporalNode.attribute( u"startExpression"_s );
277 mEndExpression = temporalNode.attribute( u"endExpression"_s );
278 mDurationFieldName = temporalNode.attribute( u"durationField"_s );
279 mDurationUnit = QgsUnitTypes::decodeTemporalUnit( temporalNode.attribute( u"durationUnit"_s, QgsUnitTypes::encodeUnit( Qgis::TemporalUnit::Minutes ) ) );
280 mFixedDuration = temporalNode.attribute( u"fixedDuration"_s ).toDouble();
281 mAccumulateFeatures = temporalNode.attribute( u"accumulate"_s, u"0"_s ).toInt();
282
283 const QDomNode rangeElement = temporalNode.namedItem( u"fixedRange"_s );
284
285 const QDomNode begin = rangeElement.namedItem( u"start"_s );
286 const QDomNode end = rangeElement.namedItem( u"end"_s );
287
288 const QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
289 const QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );
290
291 const QgsDateTimeRange range = QgsDateTimeRange( beginDate, endDate, true, mLimitMode == Qgis::VectorTemporalLimitMode::IncludeBeginIncludeEnd );
292 setFixedTemporalRange( range );
293
294 return true;
295}
296
297QDomElement QgsVectorLayerTemporalProperties::writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context )
298{
299 Q_UNUSED( context )
300 if ( element.isNull() )
301 return QDomElement();
302
303 QDomElement temporalElement = document.createElement( u"temporal"_s );
304 temporalElement.setAttribute( u"enabled"_s, isActive() ? u"1"_s : u"0"_s );
305 temporalElement.setAttribute( u"mode"_s, QString::number( static_cast< int >( mMode ) ) );
306
307 temporalElement.setAttribute( u"limitMode"_s, QString::number( static_cast< int >( mLimitMode ) ) );
308 temporalElement.setAttribute( u"startField"_s, mStartFieldName );
309 temporalElement.setAttribute( u"endField"_s, mEndFieldName );
310 temporalElement.setAttribute( u"startExpression"_s, mStartExpression );
311 temporalElement.setAttribute( u"endExpression"_s, mEndExpression );
312 temporalElement.setAttribute( u"durationField"_s, mDurationFieldName );
313 temporalElement.setAttribute( u"durationUnit"_s, QgsUnitTypes::encodeUnit( mDurationUnit ) );
314 temporalElement.setAttribute( u"fixedDuration"_s, qgsDoubleToString( mFixedDuration ) );
315 temporalElement.setAttribute( u"accumulate"_s, mAccumulateFeatures ? u"1"_s : u"0"_s );
316
317 QDomElement rangeElement = document.createElement( u"fixedRange"_s );
318
319 QDomElement startElement = document.createElement( u"start"_s );
320 QDomElement endElement = document.createElement( u"end"_s );
321
322 const QDomText startText = document.createTextNode( mFixedRange.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
323 const QDomText endText = document.createTextNode( mFixedRange.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
324 startElement.appendChild( startText );
325 endElement.appendChild( endText );
326 rangeElement.appendChild( startElement );
327 rangeElement.appendChild( endElement );
328
329 temporalElement.appendChild( rangeElement );
330
331 element.appendChild( temporalElement );
332
333 return element;
334}
335
358
360{
361 return mStartExpression;
362}
363
365{
366 mStartExpression = startExpression;
367}
368
370{
371 return mEndExpression;
372}
373
375{
376 mEndExpression = endExpression;
377}
378
380{
381 return mAccumulateFeatures;
382}
383
388
390{
391 return mFixedDuration;
392}
393
398
400{
401 return mStartFieldName;
402}
403
404void QgsVectorLayerTemporalProperties::setStartField( const QString &startFieldName )
405{
406 mStartFieldName = startFieldName;
407}
408
410{
411 return mEndFieldName;
412}
413
415{
416 mEndFieldName = field;
417}
418
420{
421 return mDurationFieldName;
422}
423
425{
426 mDurationFieldName = field;
427}
428
430{
431 return mDurationUnit;
432}
433
435{
436 mDurationUnit = units;
437}
438
439QString dateTimeExpressionLiteral( const QDateTime &datetime )
440{
441 return u"make_datetime(%1,%2,%3,%4,%5,%6)"_s.arg( datetime.date().year() )
442 .arg( datetime.date().month() )
443 .arg( datetime.date().day() )
444 .arg( datetime.time().hour() )
445 .arg( datetime.time().minute() )
446 .arg( datetime.time().second() + datetime.time().msec() / 1000.0 );
447}
448
450{
451 if ( !isActive() )
452 return QString();
453
454 auto dateTimefieldCast = [&context]( const QString &fieldName ) -> QString {
455 if ( context.layer()
456 && context.layer()->fields().lookupField( fieldName ) >= 0
457 && context.layer()->fields().at( context.layer()->fields().lookupField( fieldName ) ).type() != QMetaType::Type::QDateTime )
458 {
459 return u"to_datetime( %1 )"_s.arg( QgsExpression::quotedColumnRef( fieldName ) );
460 }
461 return QgsExpression::quotedColumnRef( fieldName );
462 };
463
464 switch ( mMode )
465 {
468 return QString();
469
471 {
472 if ( mAccumulateFeatures )
473 {
474 return u"(%1 %2 %3) OR %1 IS NULL"_s.arg( dateTimefieldCast( mStartFieldName ), filterRange.includeEnd() ? u"<="_s : u"<"_s, dateTimeExpressionLiteral( filterRange.end() ) );
475 }
476 else if ( qgsDoubleNear( mFixedDuration, 0.0 ) )
477 {
478 return u"(%1 %2 %3 AND %1 %4 %5) OR %1 IS NULL"_s.arg(
479 dateTimefieldCast( mStartFieldName ),
480 filterRange.includeBeginning() ? u">="_s : u">"_s,
481 dateTimeExpressionLiteral( filterRange.begin() ),
482 filterRange.includeEnd() ? u"<="_s : u"<"_s,
483 dateTimeExpressionLiteral( filterRange.end() )
484 );
485 }
486 else
487 {
488 // Working with features with events with a duration, so taking this duration into account (+ QgsInterval( -mFixedDuration, mDurationUnit ) ))
489 return u"(%1 %2 %3 AND %1 %4 %5) OR %1 IS NULL"_s.arg(
490 dateTimefieldCast( mStartFieldName ),
492 dateTimeExpressionLiteral( filterRange.begin() + QgsInterval( -mFixedDuration, mDurationUnit ) ),
493 filterRange.includeEnd() ? u"<="_s : u"<"_s,
494 dateTimeExpressionLiteral( filterRange.end() )
495 );
496 }
497 }
498
500 {
501 QString intervalExpression;
502 switch ( mDurationUnit )
503 {
505 intervalExpression = u"make_interval(0,0,0,0,0,0,%1/1000)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
506 break;
507
509 intervalExpression = u"make_interval(0,0,0,0,0,0,%1)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
510 break;
511
513 intervalExpression = u"make_interval(0,0,0,0,0,%1,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
514 break;
515
517 intervalExpression = u"make_interval(0,0,0,0,%1,0,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
518 break;
519
521 intervalExpression = u"make_interval(0,0,0,%1,0,0,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
522 break;
523
525 intervalExpression = u"make_interval(0,0,%1,0,0,0,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
526 break;
527
529 intervalExpression = u"make_interval(0,%1,0,0,0,0,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
530 break;
531
533 intervalExpression = u"make_interval(%1,0,0,0,0,0,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
534 break;
535
537 intervalExpression = u"make_interval(10 * %1,0,0,0,0,0,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
538 break;
539
541 intervalExpression = u"make_interval(100 * %1,0,0,0,0,0,0)"_s.arg( QgsExpression::quotedColumnRef( mDurationFieldName ) );
542 break;
543
546 return QString();
547 }
548 return u"(%1 %2 %3 OR %1 IS NULL) AND ((%1 + %4 %5 %6) OR %7 IS NULL)"_s.arg(
549 dateTimefieldCast( mStartFieldName ),
550 filterRange.includeEnd() ? u"<="_s : u"<"_s,
551 dateTimeExpressionLiteral( filterRange.end() ),
552 intervalExpression,
554 dateTimeExpressionLiteral( filterRange.begin() ),
555 QgsExpression::quotedColumnRef( mDurationFieldName )
556 );
557 }
558
560 {
561 if ( !mStartFieldName.isEmpty() && !mEndFieldName.isEmpty() )
562 {
563 return u"(%1 %2 %3 OR %1 IS NULL) AND (%4 %5 %6 OR %4 IS NULL)"_s.arg(
564 dateTimefieldCast( mStartFieldName ),
565 filterRange.includeEnd() ? u"<="_s : u"<"_s,
566 dateTimeExpressionLiteral( filterRange.end() ),
567 dateTimefieldCast( mEndFieldName ),
569 dateTimeExpressionLiteral( filterRange.begin() )
570 );
571 }
572 else if ( !mStartFieldName.isEmpty() )
573 {
574 return u"%1 %2 %3 OR %1 IS NULL"_s.arg( dateTimefieldCast( mStartFieldName ), filterRange.includeEnd() ? u"<="_s : u"<"_s, dateTimeExpressionLiteral( filterRange.end() ) );
575 }
576 else if ( !mEndFieldName.isEmpty() )
577 {
578 return u"%1 %2 %3 OR %1 IS NULL"_s
579 .arg( dateTimefieldCast( mEndFieldName ), limitMode() == Qgis::VectorTemporalLimitMode::IncludeBeginIncludeEnd ? u">="_s : u">"_s, dateTimeExpressionLiteral( filterRange.begin() ) );
580 }
581 break;
582 }
583
585 {
586 if ( !mStartExpression.isEmpty() && !mEndExpression.isEmpty() )
587 {
588 return u"((%1) %2 %3) AND ((%4) %5 %6)"_s.arg(
589 mStartExpression,
590 filterRange.includeEnd() ? u"<="_s : u"<"_s,
591 dateTimeExpressionLiteral( filterRange.end() ),
592 mEndExpression,
594 dateTimeExpressionLiteral( filterRange.begin() )
595 );
596 }
597 else if ( !mStartExpression.isEmpty() )
598 {
599 return u"(%1) %2 %3"_s.arg( mStartExpression, filterRange.includeEnd() ? u"<="_s : u"<"_s, dateTimeExpressionLiteral( filterRange.end() ) );
600 }
601 else if ( !mEndExpression.isEmpty() )
602 {
603 return u"(%1) %2 %3"_s.arg( mEndExpression, limitMode() == Qgis::VectorTemporalLimitMode::IncludeBeginIncludeEnd ? u">="_s : u">"_s, dateTimeExpressionLiteral( filterRange.begin() ) );
604 }
605 break;
606 }
607 }
608
609 return QString();
610}
611
613{
614 // Check the fields and keep the first one that matches.
615 // We assume that the user has organized the data with the
616 // more "interesting" field names first.
617 // This candidates list is a prioritized list of candidates ranked by "interestingness"!
618 // See discussion at https://github.com/qgis/QGIS/pull/30245 - this list must NOT be translated,
619 // but adding hardcoded localized variants of the strings is encouraged.
620 static const QStringList sStartCandidates {
621 u"start"_s,
622 u"begin"_s,
623 u"from"_s,
624 u"since"_s,
625 // German candidates
626 u"anfang"_s,
627 u"von"_s,
628 u"ab"_s,
629 u"seit"_s
630 };
631
632 static const QStringList sEndCandidates {
633 u"end"_s,
634 u"last"_s,
635 u"to"_s,
636 u"stop"_s,
637 // German candidates
638 u"ende"_s,
639 u"bis"_s
640 };
641
642
643 static const QStringList sSingleFieldCandidates { u"event"_s };
644
645
646 bool foundStart = false;
647 bool foundEnd = false;
648
649 for ( const QgsField &field : fields )
650 {
651 if ( field.type() != QMetaType::Type::QDate && field.type() != QMetaType::Type::QDateTime )
652 continue;
653
654 if ( !foundStart )
655 {
656 for ( const QString &candidate : sStartCandidates )
657 {
658 const QString fldName = field.name();
659 if ( fldName.indexOf( candidate, 0, Qt::CaseInsensitive ) > -1 )
660 {
661 mStartFieldName = fldName;
662 foundStart = true;
663 }
664 }
665 }
666
667 if ( !foundEnd )
668 {
669 for ( const QString &candidate : sEndCandidates )
670 {
671 const QString fldName = field.name();
672 if ( fldName.indexOf( candidate, 0, Qt::CaseInsensitive ) > -1 )
673 {
674 mEndFieldName = fldName;
675 foundEnd = true;
676 }
677 }
678 }
679
680 if ( foundStart && foundEnd )
681 break;
682 }
683
684 if ( !foundStart )
685 {
686 // loop again, looking for likely "single field" candidates
687 for ( const QgsField &field : fields )
688 {
689 if ( field.type() != QMetaType::Type::QDate && field.type() != QMetaType::Type::QDateTime )
690 continue;
691
692 for ( const QString &candidate : sSingleFieldCandidates )
693 {
694 const QString fldName = field.name();
695 if ( fldName.indexOf( candidate, 0, Qt::CaseInsensitive ) > -1 )
696 {
697 mStartFieldName = fldName;
698 foundStart = true;
699 }
700 }
701
702 if ( foundStart )
703 break;
704 }
705 }
706
707 if ( foundStart && foundEnd )
709 else if ( foundStart )
711
712 // note -- NEVER auto enable temporal properties here! It's just a helper designed
713 // to shortcut the initial field selection
714}
715
717{
718 return mLayer;
719}
720
VectorTemporalMode
Vector layer temporal feature modes.
Definition qgis.h:2669
@ FeatureDateTimeStartAndDurationFromFields
Mode when features have a field for start time and a field for event duration.
Definition qgis.h:2673
@ RedrawLayerOnly
Redraw the layer when temporal range changes, but don't apply any filtering. Useful when symbology or...
Definition qgis.h:2675
@ FeatureDateTimeStartAndEndFromExpressions
Mode when features use expressions for start and end times.
Definition qgis.h:2674
@ FeatureDateTimeInstantFromField
Mode when features have a datetime instant taken from a single field.
Definition qgis.h:2671
@ FixedTemporalRange
Mode when temporal properties have fixed start and end datetimes.
Definition qgis.h:2670
@ FeatureDateTimeStartAndEndFromFields
Mode when features have separate fields for start and end times.
Definition qgis.h:2672
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition qgis.h:2276
TemporalUnit
Temporal units.
Definition qgis.h:5316
@ IrregularStep
Special 'irregular step' time unit, used for temporal data which uses irregular, non-real-world unit ...
Definition qgis.h:5327
@ Milliseconds
Milliseconds.
Definition qgis.h:5317
@ Hours
Hours.
Definition qgis.h:5320
@ Unknown
Unknown time unit.
Definition qgis.h:5328
@ Centuries
Centuries.
Definition qgis.h:5326
@ Seconds
Seconds.
Definition qgis.h:5318
@ Weeks
Weeks.
Definition qgis.h:5322
@ Years
Years.
Definition qgis.h:5324
@ Decades
Decades.
Definition qgis.h:5325
@ Months
Months.
Definition qgis.h:5323
@ Minutes
Minutes.
Definition qgis.h:5319
@ StoresFeatureDateTimeInstantInField
Dataset has feature datetime instants stored in a single field.
Definition qgis.h:2701
@ StoresFeatureDateTimeStartAndEndInSeparateFields
Dataset stores feature start and end datetimes in separate fields.
Definition qgis.h:2702
@ HasFixedTemporalRange
Entire dataset from provider has a fixed start and end datetime.
Definition qgis.h:2700
VectorTemporalLimitMode
Mode for the handling of the limits of the filtering timeframe for vector features.
Definition qgis.h:2687
@ IncludeBeginIncludeEnd
Mode to include both limits of the filtering timeframe.
Definition qgis.h:2689
Base class for handling properties relating to a data provider's temporal capabilities.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
QMetaType::Type type
Definition qgsfield.h:63
Container of fields for a vector layer.
Definition qgsfields.h:46
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A representation of the interval between two datetime values.
Definition qgsinterval.h:52
QgsMapLayerTemporalProperties(QObject *parent, bool enabled=false)
Constructor for QgsMapLayerTemporalProperties, with the specified parent object.
Base class for all map layer types.
Definition qgsmaplayer.h:83
A container for the context for various read/write operations on objects.
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.
Definition qgsrange.h:408
T end() const
Returns the upper bound of the range.
Definition qgsrange.h:415
bool includeEnd() const
Returns true if the end is inclusive, or false if the end is exclusive.
Definition qgsrange.h:430
bool includeBeginning() const
Returns true if the beginning is inclusive, or false if the beginning is exclusive.
Definition qgsrange.h:423
bool isInfinite() const
Returns true if the range consists of all possible values.
Definition qgsrange.h:444
static Q_INVOKABLE Qgis::TemporalUnit decodeTemporalUnit(const QString &string, bool *ok=nullptr)
Decodes a temporal unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
Implementation of data provider temporal properties for QgsVectorDataProviders.
Encapsulates the context in which a QgsVectorLayer's temporal capabilities will be applied.
QgsVectorLayer * layer() const
Returns the associated layer.
void setLayer(QgsVectorLayer *layer)
Sets the associated layer.
void guessDefaultsFromFields(const QgsFields &fields)
Attempts to setup the temporal properties by scanning a set of fields and looking for standard naming...
QString endExpression() const
Returns the expression for the end time for the feature's time spans.
void setDurationField(const QString &field)
Sets the name of the duration field, which contains the duration of the event.
void setMode(Qgis::VectorTemporalMode mode)
Sets the temporal properties mode.
QgsVectorLayerTemporalProperties(QObject *parent=nullptr, bool enabled=false)
Constructor for QgsVectorLayerTemporalProperties, with the specified parent object.
void setStartExpression(const QString &expression)
Sets the expression to use for the start time for the feature's time spans.
bool isVisibleInTemporalRange(const QgsDateTimeRange &range) const override
Returns true if the layer should be visible and rendered for the specified time range.
Qgis::VectorTemporalLimitMode limitMode() const
Returns the temporal limit mode (to include or exclude begin/end limits).
void setLimitMode(Qgis::VectorTemporalLimitMode mode)
Sets the temporal limit mode (to include or exclude begin/end limits).
const QgsDateTimeRange & fixedTemporalRange() const
Returns the fixed temporal range for the layer.
double fixedDuration() const
Returns the fixed duration length, which contains the duration of the event.
bool accumulateFeatures() const
Returns true if features will be accumulated over time (i.e.
QgsTemporalProperty::Flags flags() const override
Returns flags associated to the temporal property.
void setFixedTemporalRange(const QgsDateTimeRange &range)
Sets a temporal range to apply to the whole layer.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads temporal properties from a DOM element previously written by writeXml().
void setEndExpression(const QString &endExpression)
Sets the expression to use for the end time for the feature's time spans.
QString durationField() const
Returns the name of the duration field, which contains the duration of the event.
void setDurationUnits(Qgis::TemporalUnit units)
Sets the units of the event's duration.
QString endField() const
Returns the name of the end datetime field, which contains the end time for the feature's time spans.
QString createFilterString(const QgsVectorLayerTemporalContext &context, const QgsDateTimeRange &range) const
Creates a QGIS expression filter string for filtering features within the specified context to those ...
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
Qgis::TemporalUnit durationUnits() const
Returns the units of the event's duration.
void setAccumulateFeatures(bool accumulate)
Sets whether features will be accumulated over time (i.e.
void setFixedDuration(double duration)
Sets the fixed event duration, which contains the duration of the event.
void setEndField(const QString &field)
Sets the name of the end datetime field, which contains the end time for the feature's time spans.
QgsDateTimeRange calculateTemporalExtent(QgsMapLayer *layer) const override
Attempts to calculate the overall temporal extent for the specified layer, using the settings defined...
void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities) override
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
Qgis::VectorTemporalMode mode() const
Returns the temporal properties mode.
QString startField() const
Returns the name of the start datetime field, which contains the start time for the feature's time sp...
void setStartField(const QString &field)
Sets the name of the start datetime field, which contains the start time for the feature's time spans...
QString startExpression() const
Returns the expression for the start time for the feature's time spans.
Represents a vector layer which manages a vector based dataset.
QVariant minimumValue(int index) const final
Returns the minimum value for an attribute column or an invalid variant in case of error.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
void minimumAndMaximumValue(int index, QVariant &minimum, QVariant &maximum) const
Calculates both the minimum and maximum value for an attribute column.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6893
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6975
QList< int > QgsAttributeList
Definition qgsfield.h:30
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:705
QString dateTimeExpressionLiteral(const QDateTime &datetime)