Skip to content
Permalink
Browse files

Some wmst services specify a temporal dimension using ', ' separated …

…values, so correctly parse these

Also simplify code

(cherry picked from commit fd31243)
  • Loading branch information
nyalldawson committed Feb 19, 2021
1 parent b08595e commit 107b61cc39f65c838481892ecd921acabf7eea66
Showing with 45 additions and 32 deletions.
  1. +17 −32 src/providers/wms/qgswmscapabilities.cpp
  2. +28 −0 tests/src/providers/testqgswmscapabilities.cpp
@@ -221,69 +221,54 @@ bool QgsWmsSettings::parseUri( const QString &uriString )
QgsWmstDimensionExtent QgsWmsSettings::parseTemporalExtent( const QString &extent )
{
QgsWmstDimensionExtent dimensionExtent;
if ( extent.isNull() )
if ( extent.isEmpty() )
return dimensionExtent;

const QStringList parts = extent.split( ',' );

for ( const QString &part : parts )
{
const QString item = part;
const QString item = part.trimmed();

// If item contain '/' content separator, it is an interval
if ( item.contains( '/' ) )
{
const QStringList itemParts = item.split( '/' );

QgsWmstExtentPair itemPair;
QgsWmstResolution itemResolution = itemPair.resolution;
QgsWmstDates itemDatesList = itemPair.dates;

bool itemContainResolution = false;
QgsWmstResolution itemResolution;
QgsWmstDates itemDatesList;

for ( const QString &itemPart : itemParts )
{
QString itemContent = itemPart;
QString itemContent = itemPart.trimmed();

if ( itemContent.startsWith( 'P' ) )
{
itemResolution = parseWmstResolution( itemContent );
itemContainResolution = true;
}
else
{
itemDatesList.dateTimes.append( parseWmstDateTimes( itemContent ) );
}
}

if ( itemContainResolution )
dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( itemDatesList, itemResolution ) );
else
dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( itemDatesList, QgsWmstResolution() ) );
itemContainResolution = false;
continue;
}

QgsWmstExtentPair pair;

QgsWmstResolution resolution = pair.resolution;
QgsWmstDates datesList = pair.dates;

if ( item.startsWith( 'P' ) )
{
resolution = parseWmstResolution( item );
containResolution = true;
dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( itemDatesList, itemResolution ) );
}
else
{
datesList.dateTimes.append( parseWmstDateTimes( item ) );
}
QgsWmstResolution resolution;
QgsWmstDates datesList;
if ( item.startsWith( 'P' ) )
{
resolution = parseWmstResolution( item );
}
else
{
datesList.dateTimes.append( parseWmstDateTimes( item ) );
}

if ( containResolution )
dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( datesList, resolution ) );
else
dimensionExtent.datesResolutionList.append( QgsWmstExtentPair( datesList, QgsWmstResolution() ) );
containResolution = false;
}
}

return dimensionExtent;
@@ -201,6 +201,34 @@ class TestQgsWmsCapabilities: public QObject
QCOMPARE( prop.dimensions.at( 0 ).units, QStringLiteral( "ISO8601" ) );
}

void wmstListOfTimeExtents()
{
// test parsing a fixed list of time extents
QgsWmsSettings settings;

QgsWmstDimensionExtent extent = settings.parseTemporalExtent( QStringLiteral( "1932-01-01T00:00:00Z, 1947-01-01T00:00:00Z, 1950-01-01T00:00:00Z, 1959-01-01T00:00:00Z, 1960-01-01T00:00:00Z, 1967-01-01T00:00:00Z, 1972-01-01T00:00:00Z, 1974-01-01T00:00:00Z" ) );
settings.setTimeDimensionExtent( extent );

QCOMPARE( extent.datesResolutionList.size(), 8 );
QCOMPARE( extent.datesResolutionList.at( 0 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 0 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1932, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 1 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 1 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1947, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 2 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 2 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1950, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 3 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 3 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1959, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 4 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 4 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1960, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 5 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 5 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1967, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 6 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 6 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1972, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( extent.datesResolutionList.at( 7 ).dates.dateTimes.size(), 1 );
QCOMPARE( extent.datesResolutionList.at( 7 ).dates.dateTimes.at( 0 ), QDateTime( QDate( 1974, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
}


void wmsTemporalDimension_data()
{
QTest::addColumn<QString>( "dimension" );

0 comments on commit 107b61c

Please sign in to comment.