Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for retrieving temporal extent from WMS-T version 1.1
  • Loading branch information
nyalldawson committed Apr 29, 2020
1 parent 8ba73c6 commit 99ffa0e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/providers/wms/qgswmscapabilities.cpp
Expand Up @@ -1049,8 +1049,6 @@ void QgsWmsCapabilities::parseLegendUrl( const QDomElement &element, QgsWmsLegen

void QgsWmsCapabilities::parseDimension( const QDomElement &element, QgsWmsDimensionProperty &dimensionProperty )
{

// TODO, check for the name value if it is time, implement WMS-T support
dimensionProperty.name = element.attribute( QStringLiteral( "name" ) );
dimensionProperty.units = element.attribute( QStringLiteral( "units" ) );
dimensionProperty.unitSymbol = element.attribute( QStringLiteral( "unitSymbol" ) );
Expand All @@ -1077,6 +1075,39 @@ void QgsWmsCapabilities::parseDimension( const QDomElement &element, QgsWmsDimen
dimensionProperty.extent = element.text();
}

void QgsWmsCapabilities::parseExtent( const QDomElement &element, QVector<QgsWmsDimensionProperty> &dimensionProperties )
{
const QString name = element.attribute( QStringLiteral( "name" ) );
// try to find correponsding dimension property -- i.e. we upgrade the WMS 1.1 split of Dimension and Extent to 1.3 style where Dimension holds the extent information
for ( auto it = dimensionProperties.begin(); it != dimensionProperties.end(); ++it )
{
if ( it->name == name )
{
it->extent = element.text();

it->defaultValue = element.attribute( QStringLiteral( "default" ) );

if ( !element.attribute( QStringLiteral( "multipleValues" ) ).isNull() )
{
QString multipleValuesAttribute = element.attribute( QStringLiteral( "multipleValues" ) );
it->multipleValues = ( multipleValuesAttribute == QLatin1String( "1" ) || multipleValuesAttribute == QLatin1String( "true" ) );
}

if ( !element.attribute( QStringLiteral( "nearestValue" ) ).isNull() )
{
QString nearestValueAttribute = element.attribute( QStringLiteral( "nearestValue" ) );
it->nearestValue = ( nearestValueAttribute == QLatin1String( "1" ) || nearestValueAttribute == QLatin1String( "true" ) );
}

if ( !element.attribute( QStringLiteral( "current" ) ).isNull() )
{
QString currentAttribute = element.attribute( QStringLiteral( "current" ) );
it->current = ( currentAttribute == QLatin1String( "1" ) || currentAttribute == QLatin1String( "true" ) );
}
}
}
}

void QgsWmsCapabilities::parseMetadataUrl( const QDomElement &element, QgsWmsMetadataUrlProperty &metadataUrlProperty )
{

Expand Down Expand Up @@ -1280,6 +1311,11 @@ void QgsWmsCapabilities::parseLayer( const QDomElement &element, QgsWmsLayerProp
layerProperty.dimensions << QgsWmsDimensionProperty();
parseDimension( nodeElement, layerProperty.dimensions.last() );
}
else if ( tagName == QLatin1String( "Extent" ) )
{
// upgrade WMS 1.1 style Extent/Dimension handling to WMS 1.3
parseExtent( nodeElement, layerProperty.dimensions );
}
else if ( tagName == QLatin1String( "Attribution" ) )
{
// TODO
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wms/qgswmscapabilities.h
Expand Up @@ -992,6 +992,7 @@ class QgsWmsCapabilities
void parseCapability( const QDomElement &element, QgsWmsCapabilityProperty &capabilityProperty );
void parseRequest( const QDomElement &element, QgsWmsRequestProperty &requestProperty );
void parseDimension( const QDomElement &element, QgsWmsDimensionProperty &dimensionProperty );
void parseExtent( const QDomElement &element, QVector<QgsWmsDimensionProperty> &dimensionProperties );
void parseLegendUrl( const QDomElement &element, QgsWmsLegendUrlProperty &legendUrlProperty );
void parseMetadataUrl( const QDomElement &element, QgsWmsMetadataUrlProperty &metadataUrlProperty );
void parseLayer( const QDomElement &element, QgsWmsLayerProperty &layerProperty, QgsWmsLayerProperty *parentProperty = nullptr );
Expand Down Expand Up @@ -1073,6 +1074,7 @@ class QgsWmsCapabilities
QgsCoordinateTransformContext mCoordinateTransformContext;

friend class QgsWmsProvider;
friend class TestQgsWmsCapabilities;
};


Expand Down
28 changes: 28 additions & 0 deletions tests/src/providers/testqgswmscapabilities.cpp
Expand Up @@ -156,6 +156,34 @@ class TestQgsWmsCapabilities: public QObject
QCOMPARE( outOfBoundsClosest, outofBoundsExpected );
}

void wmst11extent()
{
// test parsing WMS1.1 temporal extent
const QString layer = R"""(<Layer queryable="0" opaque="0" cascaded="0">
<Name>danger_index</Name>
<Title>danger_index</Title>
<SRS>EPSG:4326</SRS>
<LatLonBoundingBox minx="-180" miny="-90" maxx="180" maxy="90" />
<BoundingBox SRS="EPSG:4326"
minx="-180" miny="-90" maxx="180" maxy="90" />
<Dimension name="time" units="ISO8601"/>
<Extent name="time" default="2019-01-01" nearestValue="0">2018-01-01/2019-12-31</Extent>
</Layer>)""";

QDomDocument doc;
doc.setContent( layer );
QgsWmsCapabilities cap;
QgsWmsLayerProperty prop;
cap.parseLayer( doc.documentElement(), prop );

QCOMPARE( prop.name, QStringLiteral( "danger_index" ) );
QCOMPARE( prop.dimensions.size(), 1 );
QCOMPARE( prop.dimensions.at( 0 ).name, QStringLiteral( "time" ) );
QCOMPARE( prop.dimensions.at( 0 ).defaultValue, QStringLiteral( "2019-01-01" ) );
QCOMPARE( prop.dimensions.at( 0 ).extent, QStringLiteral( "2018-01-01/2019-12-31" ) );
QCOMPARE( prop.dimensions.at( 0 ).units, QStringLiteral( "ISO8601" ) );
}

};

QGSTEST_MAIN( TestQgsWmsCapabilities )
Expand Down

0 comments on commit 99ffa0e

Please sign in to comment.