Skip to content
Permalink
Browse files

using wms provider metadata functions for updates in the uri

  • Loading branch information
Samweli committed Apr 26, 2020
1 parent 2f8a51b commit c66288648c252de4333e4eaaedb773d629caafe4
Showing with 51 additions and 46 deletions.
  1. +8 −9 src/app/qgisapp.cpp
  2. +30 −29 src/gui/raster/qgsrasterlayerproperties.cpp
  3. +13 −8 src/providers/wms/qgswmsprovider.cpp
@@ -11068,24 +11068,23 @@ void QgisApp::projectTemporalRangeChanged()

if ( currentLayer->dataProvider() )
{
QgsDataSourceUri uri;
uri.setEncodedUri( currentLayer->dataProvider()->dataSourceUri() );
QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata(
currentLayer->providerType() );

if ( uri.hasParam( QStringLiteral( "temporalSource" ) ) &&
uri.param( QStringLiteral( "temporalSource" ) ) == QStringLiteral( "project" ) )
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.removeParam( QStringLiteral( "time" ) );
uri.setParam( QStringLiteral( "time" ), time );

currentLayer->dataProvider()->setDataSourceUri( uri.encodedUri() );
currentLayer->setDataSource( currentLayer->dataProvider()->dataSourceUri(), currentLayer->name(), currentLayer->providerType(), QgsDataProvider::ProviderOptions() );
uri["time"] = time;

currentLayer->setDataSource( metadata->encodeUri( uri ), currentLayer->name(), currentLayer->providerType(), QgsDataProvider::ProviderOptions() );
}
}
}
@@ -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"
@@ -1246,17 +1248,17 @@ void QgsRasterLayerProperties::updateSourceStaticTime()
mRasterLayer->dataProvider() &&
mRasterLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
{
QgsDataSourceUri uri { mRasterLayer->dataProvider()->uri() };
QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata(
mRasterLayer->providerType() );

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

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["time"] = time;
uri["temporalSource"] = QLatin1String( "provider" );
}

if ( mProjectTemporalRange->isChecked() )
@@ -1270,26 +1272,26 @@ void QgsRasterLayerProperties::updateSourceStaticTime()
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["time"] = time;
uri["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 );
uri["reference_time"] = reference_time;
}
else
{
if ( uri.contains( QStringLiteral( "reference_time" ) ) )
uri.remove( QStringLiteral( "reference_time" ) );
}
const QLatin1String enableTime = mDisableTime->isChecked() ? QLatin1String( "no" ) : QLatin1String( "yes" );

uri.removeParam( QStringLiteral( "enableTime" ) );
uri.setParam( QStringLiteral( "enableTime" ), enableTime );
uri["enableTime"] = enableTime;

mRasterLayer->setDataSource( uri.uri(), mRasterLayer->name(), mRasterLayer->providerType(), QgsDataProvider::ProviderOptions() );
mRasterLayer->setDataSource( metadata->encodeUri( uri ), mRasterLayer->name(), mRasterLayer->providerType(), QgsDataProvider::ProviderOptions() );

mRasterLayer->temporalProperties()->setIntervalHandlingMethod( static_cast< QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod >(
mFetchModeComboBox->currentData().toInt() ) );
@@ -1303,7 +1305,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 +1331,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 +1348,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( "reference_time" ) ).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,8 +1364,8 @@ 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();
const QString enableTime = uri.value( QStringLiteral( "enableTime" ) ).toString();

if ( temporalSource == QLatin1String( "provider" ) )
mStaticTemporalRange->setChecked( !time.isEmpty() );
@@ -49,6 +49,7 @@
#include "qgsexception.h"
#include "qgssettings.h"
#include "qgsogrutils.h"
#include "qgsproviderregistry.h"

#include <QNetworkRequest>
#include <QNetworkReply>
@@ -1084,15 +1085,18 @@ 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() );

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 +1106,8 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )
}
}

if ( uri.param( QStringLiteral( "enableTime" ) ) == QLatin1String( "no" ) )
if ( uri.contains( QStringLiteral( "enableTime" ) ) &&
uri.value( QStringLiteral( "enableTime" ) ) == QLatin1String( "no" ) )
{
format = "yyyy-MM-dd";
dateOnly = true;
@@ -1149,10 +1154,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( "reference_time" ) ) &&
!uri.value( QStringLiteral( "reference_time" ) ).toString().isEmpty() )
{
QString time = uri.param( QStringLiteral( "reference_time" ) );
QString time = uri.value( QStringLiteral( "reference_time" ) ).toString();

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

0 comments on commit c662886

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