Skip to content
Permalink
Browse files
Adding the possibility to include the end of the feature range
 Default temporal filtering (of vector features) in most software will
 INclude the begin/start of the feature range, but EXclude the end of it.
 So: if you filter with say a filter of 1900-1910, by default features with
 1900 will be selected, but with 1910 will NOT (exclude end).

 This commit adds the possibility (in the Temporal Features tab of the
 vector layer properties) to choose the 'limitMode'.
 The limitmode can now also be set to INclude begin AND INclude end.
 So in the above example, also the features with 1910 will be selected.

 The limitMode is written to the xml project file as temporal attribute.
  • Loading branch information
rduivenvoorde authored and nyalldawson committed Sep 8, 2021
1 parent 739aaf9 commit fb88a6dbc00c274ba2724894e659352729f200eb
Showing with 31 additions and 37 deletions.
  1. +31 −37 src/core/vector/qgsvectorlayertemporalproperties.cpp
@@ -447,16 +447,6 @@ QString QgsVectorLayerTemporalProperties::createFilterString( QgsVectorLayerTemp
if ( !isActive() )
return QString();

QgsDateTimeRange filter;
if ( limitMode() == QgsVectorLayerTemporalProperties::ModeIncludeBeginIncludeEnd )
{
filter = QgsDateTimeRange( filterRange.begin(), filterRange.end(), true, true );
}
else
{
filter = QgsDateTimeRange( filterRange.begin(), filterRange.end(), true, false ); // default is include begin, exclude end of filter
}

switch ( mMode )
{
case ModeFixedTemporalRange:
@@ -468,24 +458,24 @@ QString QgsVectorLayerTemporalProperties::createFilterString( QgsVectorLayerTemp
if ( mAccumulateFeatures )
{
return QStringLiteral( "(%1 %2 %3) OR %1 IS NULL" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ) );
filterRange.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ) );
}
else if ( qgsDoubleNear( mFixedDuration, 0.0 ) )
{
return QStringLiteral( "(%1 %2 %3 AND %1 %4 %5) OR %1 IS NULL" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
filter.includeBeginning() ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( filter.begin() ),
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ) );
filterRange.includeBeginning() ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( filterRange.begin() ),
filterRange.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ) );
}
else
{
// Working with features with events with a duration, so taking this duration into account (+ QgsInterval( -mFixedDuration, mDurationUnit ) ))
return QStringLiteral( "(%1 > %2 AND %1 %3 %4) OR %1 IS NULL" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
dateTimeExpressionLiteral( filter.begin() + QgsInterval( -mFixedDuration, mDurationUnit ) ),
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ) );
dateTimeExpressionLiteral( filterRange.begin() + QgsInterval( -mFixedDuration, mDurationUnit ) ),
( filterRange.includeEnd() or limitMode() == QgsVectorLayerTemporalProperties::ModeIncludeBeginIncludeEnd ) ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ) );
}
}

@@ -539,33 +529,36 @@ QString QgsVectorLayerTemporalProperties::createFilterString( QgsVectorLayerTemp
return QString();
}
return QStringLiteral( "(%1 %2 %3 OR %1 IS NULL) AND ((%1 + %4 > %5) OR %6 IS NULL)" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ),
( filterRange.includeEnd() or limitMode() == QgsVectorLayerTemporalProperties::ModeIncludeBeginIncludeEnd ) ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ),
intervalExpression,
dateTimeExpressionLiteral( filter.begin() ),
dateTimeExpressionLiteral( filterRange.begin() ),
QgsExpression::quotedColumnRef( mDurationFieldName ) );
}

case ModeFeatureDateTimeStartAndEndFromFields:
{
if ( !mStartFieldName.isEmpty() && !mEndFieldName.isEmpty() )
{
return QStringLiteral( "(%1 %2 %3 OR %1 IS NULL) AND (%4 > %5 OR %4 IS NULL)" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ),
return QStringLiteral( "(%1 %2 %3 OR %1 IS NULL) AND (%4 %5 %6 OR %4 IS NULL)" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
filterRange.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ),
QgsExpression::quotedColumnRef( mEndFieldName ),
dateTimeExpressionLiteral( filter.begin() ) );
limitMode() == QgsVectorLayerTemporalProperties::ModeIncludeBeginIncludeEnd ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( filterRange.begin() ) );

}
else if ( !mStartFieldName.isEmpty() )
{
return QStringLiteral( "%1 %2 %3 OR %1 IS NULL" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ) );
filterRange.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ) );
}
else if ( !mEndFieldName.isEmpty() )
{
return QStringLiteral( "%1 > %2 OR %1 IS NULL" ).arg( QgsExpression::quotedColumnRef( mEndFieldName ),
dateTimeExpressionLiteral( filter.begin() ) );
return QStringLiteral( "%1 %2 %3 OR %1 IS NULL" ).arg( QgsExpression::quotedColumnRef( mEndFieldName ),
limitMode() == QgsVectorLayerTemporalProperties::ModeIncludeBeginIncludeEnd ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( filterRange.begin() ) );
}
break;
}
@@ -575,21 +568,22 @@ QString QgsVectorLayerTemporalProperties::createFilterString( QgsVectorLayerTemp
if ( !mStartExpression.isEmpty() && !mEndExpression.isEmpty() )
{
return QStringLiteral( "((%1) %2 %3) AND ((%4) > %5)" ).arg( mStartExpression,
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ),
filterRange.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ),
mEndExpression,
dateTimeExpressionLiteral( filter.begin() ) );
dateTimeExpressionLiteral( filterRange.begin() ) );
}
else if ( !mStartExpression.isEmpty() )
{
return QStringLiteral( "(%1) %2 %3" ).arg( mStartExpression,
filter.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filter.end() ) );
filterRange.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( filterRange.end() ) );
}
else if ( !mEndExpression.isEmpty() )
{
return QStringLiteral( "(%1) > %2" ).arg( mEndExpression,
dateTimeExpressionLiteral( filter.begin() ) );
return QStringLiteral( "(%1) %2 %3" ).arg( mEndExpression,
limitMode() == QgsVectorLayerTemporalProperties::ModeIncludeBeginIncludeEnd ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( filterRange.begin() ) );
}
break;
}

0 comments on commit fb88a6d

Please sign in to comment.