Skip to content

Commit

Permalink
Adding the possibility to include the end of the feature range
Browse files Browse the repository at this point in the history
 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 fb88a6d
Showing 1 changed file with 31 additions and 37 deletions.
68 changes: 31 additions & 37 deletions src/core/vector/qgsvectorlayertemporalproperties.cpp
Expand Up @@ -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:
Expand All @@ -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() ) );
}
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit fb88a6d

Please sign in to comment.