Skip to content

Commit

Permalink
Correctly populate all available temporal ranges for WMS-T services
Browse files Browse the repository at this point in the history
which report available times using ISO8601 style duration strings
  • Loading branch information
nyalldawson committed Mar 25, 2021
1 parent 1bb042b commit 2cf7a56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/providers/wms/qgswmscapabilities.cpp
Expand Up @@ -29,6 +29,7 @@
#include "qgsunittypes.h"
#include "qgsexception.h"
#include "qgsapplication.h"
#include "qgstemporalutils.h"

// %%% copied from qgswmsprovider.cpp
static QString DEFAULT_LATLON_CRS = QStringLiteral( "CRS:84" );
Expand Down Expand Up @@ -107,7 +108,19 @@ bool QgsWmsSettings::parseUri( const QString &uriString )

const QDateTime begin = extent.dates.dateTimes.first();
const QDateTime end = extent.dates.dateTimes.last();
mAllRanges.append( QgsDateTimeRange( begin, end ) );

bool ok = false;
bool maxValuesExceeded = false;
const QList< QDateTime > dates = QgsTemporalUtils::calculateDateTimesFromISO8601( extent.originalString, ok, maxValuesExceeded );
if ( ok )
{
for ( const QDateTime &dt : dates )
mAllRanges.append( QgsDateTimeRange( dt, dt ) );
}
else
{
mAllRanges.append( QgsDateTimeRange( begin, end ) );
}
}

if ( uri.param( QStringLiteral( "referenceTimeDimensionExtent" ) ) != QString() )
Expand Down Expand Up @@ -263,7 +276,7 @@ QgsWmstDimensionExtent QgsWmsSettings::parseTemporalExtent( const QString &exten
}
}

dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( itemDatesList, itemResolution ) );
dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( itemDatesList, itemResolution, item ) );
}
else
{
Expand All @@ -278,7 +291,7 @@ QgsWmstDimensionExtent QgsWmsSettings::parseTemporalExtent( const QString &exten
datesList.dateTimes.append( parseWmstDateTimes( item ) );
}

dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( datesList, resolution ) );
dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( datesList, resolution, item ) );
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/providers/wms/qgswmscapabilities.h
Expand Up @@ -525,7 +525,10 @@ struct QgsWmstExtentPair
{
}

QgsWmstExtentPair( QgsWmstDates otherDates, QgsWmstResolution otherResolution )
QgsWmstExtentPair( QgsWmstDates otherDates, QgsWmstResolution otherResolution, const QString &originalString )
: dates( otherDates )
, resolution( otherResolution )
, originalString( originalString )
{
dates = otherDates;
resolution = otherResolution;
Expand All @@ -539,6 +542,8 @@ struct QgsWmstExtentPair

QgsWmstDates dates;
QgsWmstResolution resolution;
QString originalString;

};


Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmstsettingswidget.cpp
Expand Up @@ -96,7 +96,7 @@ void QgsWmstSettingsWidget::syncToLayer( QgsMapLayer *layer )

const QList< QgsDateTimeRange > allAvailableRanges = mRasterLayer->dataProvider()->temporalCapabilities()->allAvailableTemporalRanges();
// determine if available ranges are a set of non-contiguous instants, and if so, we show a combobox to users instead of the free-form date widgets
if ( std::all_of( allAvailableRanges.cbegin(), allAvailableRanges.cend(), []( const QgsDateTimeRange & range ) { return range.isInstant(); } ) )
if ( allAvailableRanges.size() < 50 && std::all_of( allAvailableRanges.cbegin(), allAvailableRanges.cend(), []( const QgsDateTimeRange & range ) { return range.isInstant(); } ) )
{
mStaticWmstRangeFrame->hide();
mStaticWmstChoiceFrame->show();
Expand Down

0 comments on commit 2cf7a56

Please sign in to comment.