Skip to content

Commit

Permalink
Server OAPIF datetime filter support
Browse files Browse the repository at this point in the history
with full test coverage for single values and ranges,
supports time, datetime and string fields.
  • Loading branch information
elpaso committed Oct 30, 2019
1 parent a1bfc16 commit 07bb6b7
Show file tree
Hide file tree
Showing 15 changed files with 812 additions and 477 deletions.
14 changes: 1 addition & 13 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -567,7 +567,7 @@ which is used by the layer, so any changes are immediately applied.
%End


QgsVectorLayerServerProperties *serverProperties();
QgsVectorLayerServerProperties *serverProperties() const;
%Docstring
Returns QGIS Server Properties of the vector layer

Expand Down Expand Up @@ -1904,18 +1904,6 @@ A set of attributes that are not advertised in WFS requests with QGIS server.
void setExcludeAttributesWfs( const QSet<QString> &att );
%Docstring
A set of attributes that are not advertised in WFS requests with QGIS server.
%End

QSet<QString> includeAttributesOapifTemporalFilters() const;
%Docstring
Returns the attributes that are used for temporal filtering with QGIS server OAPIF (WFS3).
\since: QGIS 3.12
%End

void setIncludeAttributesOapifTemporalFilters( const QSet<QString> &att );
%Docstring
Sets the attributes that are used for temporal filtering with QGIS server OAPIF (WFS3).
\since: QGIS 3.12
%End

virtual bool deleteAttribute( int attr );
Expand Down
Expand Up @@ -30,6 +30,7 @@ Manages QGIS Server properties for a vector layer
enum PredefinedWmsDimensionName
{
TIME,
DATE,
ELEVATION
};

Expand Down
10 changes: 9 additions & 1 deletion python/server/auto_generated/qgsserverapiutils.sip.in
Expand Up @@ -35,6 +35,14 @@ Parses a comma separated ``bbox`` into a (possibly empty) :py:class:`QgsRectangl
Z values (i.e. a 6 elements bbox) are silently discarded
%End

static QList< QgsVectorLayerServerProperties::WmsDimensionInfo > temporalDimensions( const QgsVectorLayer *layer );
%Docstring
Returns a list of temporal dimensions information for the given ``layer`` (either configured in wmsDimensions or the first date/datetime field)

.. versionadded:: 3.12
%End


struct TemporalDateInterval
{
QDate begin;
Expand Down Expand Up @@ -67,7 +75,7 @@ Parse a datetime ``interval`` and returns a TemporalDateTimeInterval
%Docstring
Parse the ``interval`` and constructs a (possibily invalid) temporal filter expression for the given ``layer``

Syntax:
Interval syntax:

interval-closed = date-time "/" date-time
interval-open-start = [".."] "/" date-time
Expand Down
26 changes: 0 additions & 26 deletions src/app/qgssourcefieldsproperties.cpp
Expand Up @@ -67,10 +67,6 @@ QgsSourceFieldsProperties::QgsSourceFieldsProperties( QgsVectorLayer *layer, QWi
wfsWi->setToolTip( tr( "Defines if this field is available in QGIS Server WFS (and OAPIF) service" ) );
mFieldsList->setHorizontalHeaderItem( AttrWFSCol, wfsWi );
mFieldsList->setHorizontalHeaderItem( AttrAliasCol, new QTableWidgetItem( tr( "Alias" ) ) );
const auto oapifWi = new QTableWidgetItem( QStringLiteral( "Temporal OAPIF" ) );
oapifWi->setToolTip( tr( "Defines if this field will be used for temporal filtering in QGIS Server OAPIF service" ) );
mFieldsList->setHorizontalHeaderItem( AttrOapifDateTimeCol, oapifWi );
mFieldsList->setHorizontalHeaderItem( AttrAliasCol, new QTableWidgetItem( tr( "Alias" ) ) );

mFieldsList->setSortingEnabled( true );
mFieldsList->sortByColumn( 0, Qt::AscendingOrder );
Expand Down Expand Up @@ -274,22 +270,6 @@ void QgsSourceFieldsProperties::setRow( int row, int idx, const QgsField &field
wfsAttrItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
mFieldsList->setItem( row, AttrWFSCol, wfsAttrItem );

// OAPIF temporal
QTableWidgetItem *oapifAttrItem = new QTableWidgetItem();
// ok, in theory, we could support any field type that
// can contain something convertible to a date/datetime, but
// let's keep it simple for now
if ( field.isDateOrTime() || field.type() == QVariant::String )
{
oapifAttrItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
oapifAttrItem->setCheckState( mLayer->includeAttributesOapifTemporalFilters().contains( field.name() ) ? Qt::Checked : Qt::Unchecked );
}
else
{
oapifAttrItem->setFlags( oapifAttrItem->flags() & ~Qt::ItemIsSelectable & ~Qt::ItemIsEnabled & ~Qt::ItemIsUserCheckable );
}
mFieldsList->setItem( row, AttrOapifDateTimeCol, oapifAttrItem );

}

bool QgsSourceFieldsProperties::addAttribute( const QgsField &field )
Expand Down Expand Up @@ -323,16 +303,10 @@ void QgsSourceFieldsProperties::apply()
{
excludeAttributesWFS.insert( mFieldsList->item( i, AttrNameCol )->text() );
}
if ( mFieldsList->item( i, AttrOapifDateTimeCol )->checkState() == Qt::Checked )
{
includeTemporalFilters.insert( mFieldsList->item( i, AttrNameCol )->text() );
}
}

mLayer->setExcludeAttributesWms( excludeAttributesWMS );
mLayer->setExcludeAttributesWfs( excludeAttributesWFS );
// Note: this is a whitelist unlike the previous two!
mLayer->setIncludeAttributesOapifTemporalFilters( includeTemporalFilters );
}

//SLOTS
Expand Down
1 change: 0 additions & 1 deletion src/app/qgssourcefieldsproperties.h
Expand Up @@ -79,7 +79,6 @@ class APP_EXPORT QgsSourceFieldsProperties : public QWidget, private Ui_QgsSourc
AttrCommentCol,
AttrWMSCol,
AttrWFSCol,
AttrOapifDateTimeCol, //! OAPIF (WFS3) datetime filter column
AttrColCount,
};

Expand Down
12 changes: 11 additions & 1 deletion src/app/qgswmsdimensiondialog.cpp
Expand Up @@ -43,7 +43,7 @@ QgsWmsDimensionDialog::QgsWmsDimensionDialog( QgsVectorLayer *layer, QStringList
connect( mFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsWmsDimensionDialog::fieldChanged );
connect( mEndFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsWmsDimensionDialog::fieldChanged );
connect( mNameComboBox, &QComboBox::editTextChanged, this, &QgsWmsDimensionDialog::nameChanged );
connect( mDefaultDisplayComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsWmsDimensionDialog::defaultDisplayChanged );
connect( mDefaultDisplayComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsWmsDimensionDialog::defaultDisplayChanged );

// Set available names
const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsVectorLayerServerProperties::PredefinedWmsDimensionName>() );
Expand Down Expand Up @@ -155,6 +155,16 @@ void QgsWmsDimensionDialog::nameChanged( const QString &name )
mUnitSymbolLabel->setEnabled( false );
mUnitSymbolLineEdit->setEnabled( false );
}
if ( data == QgsVectorLayerServerProperties::DATE )
{
mFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::Date );
mEndFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::Date );
mUnitsLineEdit->setText( QStringLiteral( "ISO8601" ) );
mUnitsLabel->setEnabled( false );
mUnitsLineEdit->setEnabled( false );
mUnitSymbolLabel->setEnabled( false );
mUnitSymbolLineEdit->setEnabled( false );
}
else if ( data == QgsVectorLayerServerProperties::ELEVATION )
{
mFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgswmsdimensiondialog.h
Expand Up @@ -24,6 +24,17 @@

class QgsVectorLayer;

/**
* The QgsWmsDimensionDialog class provides an inteface for WMS/OAPIF (WFS3) dimensions configuration
* Available pre-defined dimensions are
*
* - DATE (supported by OAPIF only)
* - TIME(supported by WMS and OAPIF)
* - ELEVATION (supported by WMS only)
*
* Dimensions can also be configured as ranges by defining an "end" field that contains the
* upper value of the range.
*/
class APP_EXPORT QgsWmsDimensionDialog: public QDialog, private Ui::QgsWmsDimensionDialogBase
{
Q_OBJECT
Expand Down
14 changes: 1 addition & 13 deletions src/core/qgsvectorlayer.h
Expand Up @@ -692,7 +692,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* Returns QGIS Server Properties of the vector layer
* \since QGIS 3.10
*/
QgsVectorLayerServerProperties *serverProperties() { return mServerProperties.get(); }
QgsVectorLayerServerProperties *serverProperties() const { return mServerProperties.get(); }

/**
* Returns the number of features that are selected in this layer.
Expand Down Expand Up @@ -1775,18 +1775,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
void setExcludeAttributesWfs( const QSet<QString> &att ) { mExcludeAttributesWFS = att; }

/**
* Returns the attributes that are used for temporal filtering with QGIS server OAPIF (WFS3).
* \since: QGIS 3.12
*/
QSet<QString> includeAttributesOapifTemporalFilters() const { return mIncludeAttributesOapifTemporalFilters; }

/**
* Sets the attributes that are used for temporal filtering with QGIS server OAPIF (WFS3).
* \since: QGIS 3.12
*/
void setIncludeAttributesOapifTemporalFilters( const QSet<QString> &att ) { mIncludeAttributesOapifTemporalFilters = att; }

/**
* Deletes an attribute field (but does not commit it).
*
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayerserverproperties.h
Expand Up @@ -48,6 +48,7 @@ class CORE_EXPORT QgsVectorLayerServerProperties
enum PredefinedWmsDimensionName
{
TIME,
DATE,
ELEVATION
};
Q_ENUM( PredefinedWmsDimensionName )
Expand Down

0 comments on commit 07bb6b7

Please sign in to comment.