Skip to content
Permalink
Browse files

Merge pull request #35741 from Samweli/auto_update_layer_project_range

Update WMS-T layers project temporal range
  • Loading branch information
elpaso committed Apr 30, 2020
2 parents 74aa54b + b8fee83 commit 759db0a41410299996e8aff98dc0af62dc627896
@@ -1189,7 +1189,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

mMapCanvas->setTemporalController( mTemporalControllerWidget->temporalController() );


QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsAppDirectoryItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectHomeItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectItemGuiProvider() );
@@ -4080,6 +4079,8 @@ void QgisApp::setupConnections()
}
} );

connect( QgsProject::instance()->timeSettings(), &QgsProjectTimeSettings::temporalRangeChanged, this, &QgisApp::projectTemporalRangeChanged );

// connect legend signals
connect( this, &QgisApp::activeLayerChanged,
this, &QgisApp::activateDeactivateLayerRelatedActions );
@@ -11056,6 +11057,40 @@ void QgisApp::projectCrsChanged()
}
}

void QgisApp::projectTemporalRangeChanged()
{
QMap<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
QgsMapLayer *currentLayer = nullptr;

for ( QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin(); it != layers.constEnd(); ++it )
{
currentLayer = it.value();

if ( currentLayer->dataProvider() )
{
QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata(
currentLayer->providerType() );

QVariantMap uri = metadata->decodeUri( currentLayer->dataProvider()->dataSourceUri() );

if ( uri.contains( QStringLiteral( "temporalSource" ) ) &&
uri.value( QStringLiteral( "temporalSource" ) ).toString() == QStringLiteral( "project" ) )
{
QgsDateTimeRange range = QgsProject::instance()->timeSettings()->temporalRange();
if ( range.begin().isValid() && range.end().isValid() )
{
QString time = range.begin().toString( Qt::ISODateWithMs ) + '/' +
range.end().toString( Qt::ISODateWithMs );

uri[ QStringLiteral( "time" ) ] = time;

currentLayer->setDataSource( metadata->encodeUri( uri ), currentLayer->name(), currentLayer->providerType(), QgsDataProvider::ProviderOptions() );
}
}
}
}
}

// toggle overview status
void QgisApp::isInOverview()
{
@@ -1788,6 +1788,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! handle project crs changes
void projectCrsChanged();

//! Updates the temporal range in layers that are using project temporal range.
void projectTemporalRangeChanged();

void onActiveLayerChanged( QgsMapLayer *layer );

/**
@@ -127,6 +127,11 @@ QgsRasterLayer::QgsRasterLayer( const QString &uri,

setDataSource( uri, baseName, providerKey, providerOptions, options.loadDefaultStyle );

if ( mValid )
{
mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );
}

} // QgsRasterLayer ctor

QgsRasterLayer::~QgsRasterLayer()
@@ -871,8 +876,6 @@ void QgsRasterLayer::setDataSource( const QString &dataSource, const QString &ba

if ( mValid )
{
mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );

// load default style
bool defaultLoadedFlag = false;
bool restoredStyle = false;
@@ -60,6 +60,8 @@
#include "qgsfileutils.h"
#include "qgswebview.h"
#include "qgsvectorlayer.h"
#include "qgsprovidermetadata.h"
#include "qgsproviderregistry.h"

#include "qgsrasterlayertemporalpropertieswidget.h"
#include "qgsprojecttimesettings.h"
@@ -1242,21 +1244,21 @@ void QgsRasterLayerProperties::apply()

void QgsRasterLayerProperties::updateSourceStaticTime()
{
QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata(
mRasterLayer->providerType() );
QVariantMap uri = metadata->decodeUri( mRasterLayer->dataProvider()->dataSourceUri() );
uri[ QStringLiteral( "allowTemporalUpdates" ) ] = mWmstGroup->isChecked() ;

if ( mWmstGroup->isEnabled() &&
mRasterLayer->dataProvider() &&
mRasterLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
{
QgsDataSourceUri uri { mRasterLayer->dataProvider()->uri() };

if ( mStaticTemporalRange->isChecked() )
{
QString time = mStartStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs ) + '/' +
mEndStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
uri.removeParam( QStringLiteral( "time" ) );
uri.setParam( QStringLiteral( "time" ), time );

uri.removeParam( QStringLiteral( "temporalSource" ) );
uri.setParam( QStringLiteral( "temporalSource" ), QLatin1String( "provider" ) );
uri[ QStringLiteral( "time" ) ] = time;
uri[ QStringLiteral( "temporalSource" ) ] = QLatin1String( "provider" );
}

if ( mProjectTemporalRange->isChecked() )
@@ -1267,33 +1269,32 @@ void QgsRasterLayerProperties::updateSourceStaticTime()
range = QgsProject::instance()->timeSettings()->temporalRange();
if ( range.begin().isValid() && range.end().isValid() )
{
QString time = range.begin().toString( Qt::ISODateWithMs ) + "/" +
QString time = range.begin().toString( Qt::ISODateWithMs ) + '/' +
range.end().toString( Qt::ISODateWithMs );

uri.removeParam( QStringLiteral( "time" ) );
uri.setParam( QStringLiteral( "time" ), time );

uri.removeParam( QStringLiteral( "temporalSource" ) );
uri.setParam( QStringLiteral( "temporalSource" ), QLatin1String( "project" ) );
uri[ QStringLiteral( "time" ) ] = time;
uri[ QStringLiteral( "temporalSource" ) ] = QLatin1String( "project" );
}
}

if ( mReferenceTime->isChecked() )
{
QString reference_time = mReferenceDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
uri.removeParam( QStringLiteral( "reference_time" ) );
uri.setParam( QStringLiteral( "reference_time" ), reference_time );
QString referenceTime = mReferenceDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
uri[ QStringLiteral( "referenceTime" ) ] = referenceTime;
}
const QLatin1String enableTime = mDisableTime->isChecked() ? QLatin1String( "no" ) : QLatin1String( "yes" );

uri.removeParam( QStringLiteral( "enableTime" ) );
uri.setParam( QStringLiteral( "enableTime" ), enableTime );

mRasterLayer->setDataSource( uri.uri(), mRasterLayer->name(), mRasterLayer->providerType(), QgsDataProvider::ProviderOptions() );
else
{
if ( uri.contains( QStringLiteral( "referenceTime" ) ) )
uri.remove( QStringLiteral( "referenceTime" ) );
}
bool enableTime = !mDisableTime->isChecked();

uri[ QStringLiteral( "enableTime" ) ] = enableTime;
mRasterLayer->temporalProperties()->setIntervalHandlingMethod( static_cast< QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod >(
mFetchModeComboBox->currentData().toInt() ) );
}
mRasterLayer->setDataSource( metadata->encodeUri( uri ), mRasterLayer->name(), mRasterLayer->providerType(), QgsDataProvider::ProviderOptions() );

}

void QgsRasterLayerProperties::setSourceStaticTimeState()
@@ -1303,7 +1304,10 @@ void QgsRasterLayerProperties::setSourceStaticTimeState()
const QgsDateTimeRange availableProviderRange = mRasterLayer->dataProvider()->temporalCapabilities()->availableTemporalRange();
const QgsDateTimeRange availableReferenceRange = mRasterLayer->dataProvider()->temporalCapabilities()->availableReferenceTemporalRange();

QgsDataSourceUri uri { mRasterLayer->dataProvider()->uri() };
QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata(
mRasterLayer->providerType() );

QVariantMap uri = metadata->decodeUri( mRasterLayer->dataProvider()->dataSourceUri() );

mStartStaticDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
mEndStaticDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
@@ -1326,15 +1330,15 @@ void QgsRasterLayerProperties::setSourceStaticTimeState()
mReferenceDateTimeEdit->setDateTime( availableReferenceRange.begin() );
}

const QString time = uri.param( QStringLiteral( "time" ) );
const QString time = uri.value( QStringLiteral( "time" ) ).toString();
if ( !time.isEmpty() )
{
QStringList parts = time.split( '/' );
mStartStaticDateTimeEdit->setDateTime( QDateTime::fromString( parts.at( 0 ), Qt::ISODateWithMs ) );
mEndStaticDateTimeEdit->setDateTime( QDateTime::fromString( parts.at( 1 ), Qt::ISODateWithMs ) );
}

const QString referenceTimeExtent = uri.param( QStringLiteral( "referenceTimeDimensionExtent" ) );
const QString referenceTimeExtent = uri.value( QStringLiteral( "referenceTimeDimensionExtent" ) ).toString();

mReferenceTime->setEnabled( !referenceTimeExtent.isEmpty() );
mReferenceDateTimeEdit->setVisible( !referenceTimeExtent.isEmpty() );
@@ -1343,17 +1347,13 @@ void QgsRasterLayerProperties::setSourceStaticTimeState()
tr( "There is no reference time in the layer's capabilities." ) : QString();
mReferenceTimeLabel->setText( referenceTimeLabelText );

const QString referenceTime = uri.param( QStringLiteral( "reference_time" ) );
const QString referenceTime = uri.value( QStringLiteral( "referenceTime" ) ).toString();

mReferenceTime->setChecked( !referenceTime.isEmpty() );

if ( !referenceTime.isEmpty() && !referenceTimeExtent.isEmpty() )
{
if ( referenceTime.contains( '/' ) )
{
QStringList parts = time.split( '/' );
mReferenceDateTimeEdit->setDateTime( QDateTime::fromString( parts.at( 0 ), Qt::ISODateWithMs ) );
}
else
mReferenceDateTimeEdit->setDateTime( QDateTime::fromString( referenceTime, Qt::ISODateWithMs ) );
mReferenceDateTimeEdit->setDateTime( QDateTime::fromString( referenceTime, Qt::ISODateWithMs ) );
}

mFetchModeComboBox->addItem( tr( "Use Whole Temporal Range" ), QgsRasterDataProviderTemporalCapabilities::MatchUsingWholeRange );
@@ -1363,15 +1363,18 @@ void QgsRasterLayerProperties::setSourceStaticTimeState()
mFetchModeComboBox->addItem( tr( "Closest Match to End of Range" ), QgsRasterDataProviderTemporalCapabilities::FindClosestMatchToEndOfRange );
mFetchModeComboBox->setCurrentIndex( mFetchModeComboBox->findData( mRasterLayer->temporalProperties()->intervalHandlingMethod() ) );

const QString temporalSource = uri.param( QStringLiteral( "temporalSource" ) );
const QString enableTime = uri.param( QStringLiteral( "enableTime" ) );
const QString temporalSource = uri.value( QStringLiteral( "temporalSource" ) ).toString();
bool enableTime = uri.value( QStringLiteral( "enableTime" ), true ).toBool();

if ( temporalSource == QLatin1String( "provider" ) )
mStaticTemporalRange->setChecked( !time.isEmpty() );
else if ( temporalSource == QLatin1String( "project" ) )
mProjectTemporalRange->setChecked( !time.isEmpty() );

mDisableTime->setChecked( enableTime == QLatin1String( "no" ) );
mDisableTime->setChecked( !enableTime );

mWmstGroup->setChecked( uri.contains( QStringLiteral( "allowTemporalUpdates" ) ) &&
uri.value( QStringLiteral( "allowTemporalUpdates" ), true ).toBool() );
}
}

@@ -302,7 +302,6 @@ QString QgsWMSItemBase::createUri()
if ( mDataSourceUri.param( QLatin1String( "type" ) ) == QLatin1String( "wmst" ) )
{
mDataSourceUri.setParam( QLatin1String( "temporalSource" ), QLatin1String( "provider" ) );
mDataSourceUri.setParam( QLatin1String( "enableTime" ), QLatin1String( "yes" ) );
}

QString format;
@@ -61,7 +61,7 @@ class QgsWMSItemBase
* - "timeDimensionExtent": the layer's time dimension extent it is available
* - "referencetimeDimensionExtent": reference time extent for the bi-temporal dimension layers
* - "time": time value of the current layer data from the provider
* - "reference_time": reference time value of the current of the layer data, this is applicable for the
* - "referenceTime": reference time value of the current of the layer data, this is applicable for the
* bi-temporal dimension layers
* - "allowTemporalUpdates": whether to allow updates on temporal parameters on this uri
* - "temporalSource": the source of the layer's temporal range, can be either "provider" or "project"
@@ -49,6 +49,7 @@
#include "qgsexception.h"
#include "qgssettings.h"
#include "qgsogrutils.h"
#include "qgsproviderregistry.h"

#include <QNetworkRequest>
#include <QNetworkReply>
@@ -1084,15 +1085,22 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )
QgsDateTimeRange range = temporalCapabilities()->requestedTemporalRange();

QString format { QStringLiteral( "yyyy-MM-ddThh:mm:ssZ" ) };
QgsDataSourceUri uri { dataSourceUri() };
bool dateOnly = false;

QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( "wms" );

QVariantMap uri = metadata->decodeUri( dataSourceUri() );

// Skip fetching if updates are not allowed
if ( !uri.value( QStringLiteral( "allowTemporalUpdates" ), true ).toBool() )
return;

if ( range.isInfinite() )
{
if ( uri.hasParam( QStringLiteral( "time" ) ) &&
!uri.param( QStringLiteral( "time" ) ).isEmpty() )
if ( uri.contains( QStringLiteral( "time" ) ) &&
!uri.value( QStringLiteral( "time" ) ).toString().isEmpty() )
{
QString time = uri.param( QStringLiteral( "time" ) );
QString time = uri.value( QStringLiteral( "time" ) ).toString();
QStringList timeParts = time.split( '/' );

QDateTime start = QDateTime::fromString( timeParts.at( 0 ), Qt::ISODateWithMs );
@@ -1102,7 +1110,7 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )
}
}

if ( uri.param( QStringLiteral( "enableTime" ) ) == QLatin1String( "no" ) )
if ( !uri.value( QStringLiteral( "enableTime" ), true ).toBool() )
{
format = "yyyy-MM-dd";
dateOnly = true;
@@ -1149,10 +1157,10 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )
}

// If the data provider has bi-temporal properties and they are enabled
if ( uri.hasParam( QStringLiteral( "reference_time" ) ) &&
!uri.param( QStringLiteral( "reference_time" ) ).isEmpty() )
if ( uri.contains( QStringLiteral( "referenceTime" ) ) &&
!uri.value( QStringLiteral( "referenceTime" ) ).toString().isEmpty() )
{
QString time = uri.param( QStringLiteral( "reference_time" ) );
QString time = uri.value( QStringLiteral( "referenceTime" ) ).toString();

QDateTime dateTime = QDateTime::fromString( time, Qt::ISODateWithMs );

@@ -1053,7 +1053,6 @@ void QgsWMSSourceSelect::collectDimensions( QStringList &layers, QgsDataSourceUr
if ( uri.param( QLatin1String( "type" ) ) == QLatin1String( "wmst" ) )
{
uri.setParam( QLatin1String( "temporalSource" ), QLatin1String( "provider" ) );
uri.setParam( QLatin1String( "enableTime" ), QLatin1String( "yes" ) );
}

}

0 comments on commit 759db0a

Please sign in to comment.
You can’t perform that action at this time.