Skip to content

Commit bc87d51

Browse files
committedFeb 23, 2014
wms provider [hopefully fully adapted to merged threading]
* store all given bounding boxes and if available choose the given bbox for the requested srid, otherwise pick one that transforms fin(it)e * remove unused mCoordinateTransform * wmts: show tile matrix size with warnings when the matrix is not large enough to cover the layer extents
1 parent 4e162fa commit bc87d51

File tree

3 files changed

+483
-350
lines changed

3 files changed

+483
-350
lines changed
 

‎src/providers/wms/qgswmscapabilities.cpp

Lines changed: 100 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ bool QgsWmsSettings::parseUri( QString uriString )
103103

104104

105105
QgsWmsCapabilities::QgsWmsCapabilities()
106-
: mValid( false )
107-
, mLayerCount( -1 )
106+
: mValid( false )
107+
, mLayerCount( -1 )
108108
{
109109
}
110110

@@ -591,7 +591,7 @@ void QgsWmsCapabilities::parseCapability( QDomElement const & e, QgsWmsCapabilit
591591
else if ( name == "GetFeatureInfo" )
592592
{
593593
ot = &capabilityProperty.request.getFeatureInfo;
594-
}
594+
}
595595
else if ( name == "GetLegendGraphic" || name == "sld:GetLegendGraphic" )
596596
{
597597
ot = &capabilityProperty.request.getLegendGraphic;
@@ -692,7 +692,7 @@ void QgsWmsCapabilities::parseLegendUrl( QDomElement const & e, QgsWmsLegendUrlP
692692
}
693693

694694
void QgsWmsCapabilities::parseLayer( QDomElement const & e, QgsWmsLayerProperty& layerProperty,
695-
QgsWmsLayerProperty *parentProperty )
695+
QgsWmsLayerProperty *parentProperty )
696696
{
697697
QgsDebugMsg( "entering." );
698698

@@ -732,7 +732,7 @@ void QgsWmsCapabilities::parseLayer( QDomElement const & e, QgsWmsLayerProperty&
732732
// Ref: 7.2.4.8 Inheritance of layer properties
733733
subLayerProperty.style = layerProperty.style;
734734
subLayerProperty.crs = layerProperty.crs;
735-
subLayerProperty.boundingBox = layerProperty.boundingBox;
735+
subLayerProperty.boundingBoxes = layerProperty.boundingBoxes;
736736
subLayerProperty.ex_GeographicBoundingBox = layerProperty.ex_GeographicBoundingBox;
737737
// TODO
738738

@@ -846,7 +846,7 @@ void QgsWmsCapabilities::parseLayer( QDomElement const & e, QgsWmsLayerProperty&
846846
bbox.box = invAxisBbox;
847847
}
848848

849-
layerProperty.boundingBox.push_back( bbox );
849+
layerProperty.boundingBoxes << bbox;
850850
}
851851
else
852852
{
@@ -1180,20 +1180,33 @@ void QgsWmsCapabilities::parseTileSetProfile( QDomElement const &e )
11801180
}
11811181
else if ( tagName == "BoundingBox" )
11821182
{
1183-
l.boundingBox.box = QgsRectangle(
1184-
e1.attribute( "minx" ).toDouble(),
1185-
e1.attribute( "miny" ).toDouble(),
1186-
e1.attribute( "maxx" ).toDouble(),
1187-
e1.attribute( "maxy" ).toDouble()
1188-
);
1183+
QgsWmsBoundingBoxProperty bb;
1184+
bb.box = QgsRectangle(
1185+
e1.attribute( "minx" ).toDouble(),
1186+
e1.attribute( "miny" ).toDouble(),
1187+
e1.attribute( "maxx" ).toDouble(),
1188+
e1.attribute( "maxy" ).toDouble()
1189+
);
11891190
if ( e1.hasAttribute( "SRS" ) )
1190-
l.boundingBox.crs = e1.attribute( "SRS" );
1191+
bb.crs = e1.attribute( "SRS" );
11911192
else if ( e1.hasAttribute( "srs" ) )
1192-
l.boundingBox.crs = e1.attribute( "srs" );
1193+
bb.crs = e1.attribute( "srs" );
11931194
else if ( e1.hasAttribute( "CRS" ) )
1194-
l.boundingBox.crs = e1.attribute( "CRS" );
1195+
bb.crs = e1.attribute( "CRS" );
11951196
else if ( e1.hasAttribute( "crs" ) )
1196-
l.boundingBox.crs = e1.attribute( "crs" );
1197+
bb.crs = e1.attribute( "crs" );
1198+
else
1199+
QgsDebugMsg( "crs of bounding box undefined" );
1200+
1201+
if ( !bb.crs.isEmpty() )
1202+
{
1203+
QgsCoordinateReferenceSystem crs;
1204+
crs.createFromOgcWmsCrs( bb.crs );
1205+
if ( crs.isValid() )
1206+
bb.crs = crs.authid();
1207+
1208+
l.boundingBoxes << bb;
1209+
}
11971210
}
11981211
else if ( tagName == "Resolutions" )
11991212
{
@@ -1225,9 +1238,10 @@ void QgsWmsCapabilities::parseTileSetProfile( QDomElement const &e )
12251238
{
12261239
double r = rS.toDouble();
12271240
m.identifier = QString::number( i );
1228-
m.matrixWidth = ceil( l.boundingBox.box.width() / m.tileWidth / r );
1229-
m.matrixHeight = ceil( l.boundingBox.box.height() / m.tileHeight / r );
1230-
m.topLeft = QgsPoint( l.boundingBox.box.xMinimum(), l.boundingBox.box.yMinimum() + m.matrixHeight * m.tileHeight * r );
1241+
Q_ASSERT( l.boundingBoxes.size() == 1 );
1242+
m.matrixWidth = ceil( l.boundingBoxes[0].box.width() / m.tileWidth / r );
1243+
m.matrixHeight = ceil( l.boundingBoxes[0].box.height() / m.tileHeight / r );
1244+
m.topLeft = QgsPoint( l.boundingBoxes[0].box.xMinimum(), l.boundingBoxes[0].box.yMinimum() + m.matrixHeight * m.tileHeight * r );
12311245
ms.tileMatrices.insert( r, m );
12321246
i++;
12331247
}
@@ -1242,20 +1256,22 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
12421256
//
12431257

12441258
mTileMatrixSets.clear();
1245-
for ( QDomNode n0 = e.firstChildElement( "TileMatrixSet" ); !n0.isNull(); n0 = n0.nextSiblingElement( "TileMatrixSet" ) )
1259+
for ( QDomElement e0 = e.firstChildElement( "TileMatrixSet" );
1260+
!e0.isNull();
1261+
e0 = e0.nextSiblingElement( "TileMatrixSet" ) )
12461262
{
12471263
QgsWmtsTileMatrixSet s;
1248-
s.identifier = n0.firstChildElement( "ows:Identifier" ).text();
1249-
s.title = n0.firstChildElement( "ows:Title" ).text();
1250-
s.abstract = n0.firstChildElement( "ows:Abstract" ).text();
1251-
parseKeywords( n0, s.keywords );
1264+
s.identifier = e0.firstChildElement( "ows:Identifier" ).text();
1265+
s.title = e0.firstChildElement( "ows:Title" ).text();
1266+
s.abstract = e0.firstChildElement( "ows:Abstract" ).text();
1267+
parseKeywords( e0, s.keywords );
12521268

1253-
QString supportedCRS = n0.firstChildElement( "ows:SupportedCRS" ).text();
1269+
QString supportedCRS = e0.firstChildElement( "ows:SupportedCRS" ).text();
12541270

12551271
QgsCoordinateReferenceSystem crs;
12561272
crs.createFromOgcWmsCrs( supportedCRS );
12571273

1258-
s.wkScaleSet = n0.firstChildElement( "WellKnownScaleSet" ).text();
1274+
s.wkScaleSet = e0.firstChildElement( "WellKnownScaleSet" ).text();
12591275

12601276
double metersPerUnit = QGis::fromUnitToUnitFactor( crs.mapUnits(), QGis::Meters );
12611277

@@ -1273,20 +1289,20 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
12731289
.arg( invert ? "yes" : "no" )
12741290
);
12751291

1276-
for ( QDomNode n1 = n0.firstChildElement( "TileMatrix" );
1277-
!n1.isNull();
1278-
n1 = n1.nextSiblingElement( "TileMatrix" ) )
1292+
for ( QDomElement e1 = e0.firstChildElement( "TileMatrix" );
1293+
!e1.isNull();
1294+
e1 = e1.nextSiblingElement( "TileMatrix" ) )
12791295
{
12801296
QgsWmtsTileMatrix m;
12811297

1282-
m.identifier = n1.firstChildElement( "ows:Identifier" ).text();
1283-
m.title = n1.firstChildElement( "ows:Title" ).text();
1284-
m.abstract = n1.firstChildElement( "ows:Abstract" ).text();
1285-
parseKeywords( n1, m.keywords );
1298+
m.identifier = e1.firstChildElement( "ows:Identifier" ).text();
1299+
m.title = e1.firstChildElement( "ows:Title" ).text();
1300+
m.abstract = e1.firstChildElement( "ows:Abstract" ).text();
1301+
parseKeywords( e1, m.keywords );
12861302

1287-
m.scaleDenom = n1.firstChildElement( "ScaleDenominator" ).text().toDouble();
1303+
m.scaleDenom = e1.firstChildElement( "ScaleDenominator" ).text().toDouble();
12881304

1289-
QStringList topLeft = n1.firstChildElement( "TopLeftCorner" ).text().split( " " );
1305+
QStringList topLeft = e1.firstChildElement( "TopLeftCorner" ).text().split( " " );
12901306
if ( topLeft.size() == 2 )
12911307
{
12921308
if ( invert )
@@ -1304,10 +1320,10 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
13041320
continue;
13051321
}
13061322

1307-
m.tileWidth = n1.firstChildElement( "TileWidth" ).text().toInt();
1308-
m.tileHeight = n1.firstChildElement( "TileHeight" ).text().toInt();
1309-
m.matrixWidth = n1.firstChildElement( "MatrixWidth" ).text().toInt();
1310-
m.matrixHeight = n1.firstChildElement( "MatrixHeight" ).text().toInt();
1323+
m.tileWidth = e1.firstChildElement( "TileWidth" ).text().toInt();
1324+
m.tileHeight = e1.firstChildElement( "TileHeight" ).text().toInt();
1325+
m.matrixWidth = e1.firstChildElement( "MatrixWidth" ).text().toInt();
1326+
m.matrixHeight = e1.firstChildElement( "MatrixHeight" ).text().toInt();
13111327

13121328
double res = m.scaleDenom * 0.00028 / metersPerUnit;
13131329

@@ -1344,7 +1360,7 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
13441360
l.abstract = e0.firstChildElement( "ows:Abstract" ).text();
13451361
parseKeywords( e0, l.keywords );
13461362

1347-
l.boundingBox.crs = "";
1363+
QgsWmsBoundingBoxProperty bb;
13481364

13491365
QDomElement bbox = e0.firstChildElement( "ows:WGS84BoundingBox" );
13501366
if ( !bbox.isNull() )
@@ -1354,43 +1370,46 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
13541370

13551371
if ( ll.size() == 2 && ur.size() == 2 )
13561372
{
1357-
l.boundingBox.box = QgsRectangle( QgsPoint( ll[0].toDouble(), ll[1].toDouble() ),
1358-
QgsPoint( ur[0].toDouble(), ur[1].toDouble() ) );
1359-
l.boundingBox.crs = DEFAULT_LATLON_CRS;
1373+
bb.crs = DEFAULT_LATLON_CRS;
1374+
bb.box = QgsRectangle( QgsPoint( ll[0].toDouble(), ll[1].toDouble() ),
1375+
QgsPoint( ur[0].toDouble(), ur[1].toDouble() ) );
13601376
}
13611377
}
13621378

1363-
if ( l.boundingBox.crs.isEmpty() )
1379+
for ( bbox = e0.firstChildElement( "ows:BoundingBox" );
1380+
!bbox.isNull();
1381+
bbox = bbox.nextSiblingElement( "ows:BoundingBox" ) )
13641382
{
1365-
bbox = e0.firstChildElement( "ows:BoundingBox" );
1366-
if ( !bbox.isNull() )
1383+
QStringList ll = bbox.firstChildElement( "ows:LowerCorner" ).text().split( " " );
1384+
QStringList ur = bbox.firstChildElement( "ows:UpperCorner" ).text().split( " " );
1385+
1386+
if ( ll.size() == 2 && ur.size() == 2 )
13671387
{
1368-
QStringList ll = bbox.firstChildElement( "ows:LowerCorner" ).text().split( " " );
1369-
QStringList ur = bbox.firstChildElement( "ows:UpperCorner" ).text().split( " " );
1388+
bb.box = QgsRectangle( QgsPoint( ll[0].toDouble(), ll[1].toDouble() ),
1389+
QgsPoint( ur[0].toDouble(), ur[1].toDouble() ) );
1390+
1391+
if ( bbox.hasAttribute( "SRS" ) )
1392+
bb.crs = bbox.attribute( "SRS" );
1393+
else if ( bbox.hasAttribute( "srs" ) )
1394+
bb.crs = bbox.attribute( "srs" );
1395+
else if ( bbox.hasAttribute( "CRS" ) )
1396+
bb.crs = bbox.attribute( "CRS" );
1397+
else if ( bbox.hasAttribute( "crs" ) )
1398+
bb.crs = bbox.attribute( "crs" );
1399+
else
1400+
QgsDebugMsg( "crs of bounding box undefined" );
13701401

1371-
if ( ll.size() == 2 && ur.size() == 2 )
1402+
if ( !bb.crs.isEmpty() )
13721403
{
1373-
l.boundingBox.box = QgsRectangle( QgsPoint( ll[0].toDouble(), ll[1].toDouble() ),
1374-
QgsPoint( ur[0].toDouble(), ur[1].toDouble() ) );
1375-
1376-
if ( bbox.hasAttribute( "SRS" ) )
1377-
l.boundingBox.crs = bbox.attribute( "SRS" );
1378-
else if ( bbox.hasAttribute( "srs" ) )
1379-
l.boundingBox.crs = bbox.attribute( "srs" );
1380-
else if ( bbox.hasAttribute( "CRS" ) )
1381-
l.boundingBox.crs = bbox.attribute( "CRS" );
1382-
else if ( bbox.hasAttribute( "crs" ) )
1383-
l.boundingBox.crs = bbox.attribute( "crs" );
1404+
QgsCoordinateReferenceSystem crs;
1405+
crs.createFromOgcWmsCrs( bb.crs );
1406+
if ( crs.isValid() )
1407+
bb.crs = crs.authid();
1408+
l.boundingBoxes << bb;
13841409
}
13851410
}
13861411
}
13871412

1388-
if ( l.boundingBox.crs.isEmpty() )
1389-
{
1390-
l.boundingBox.box = QgsRectangle( -180.0, -90.0, 180.0, 90.0 );
1391-
l.boundingBox.crs = DEFAULT_LATLON_CRS;
1392-
}
1393-
13941413
for ( QDomElement e1 = e0.firstChildElement( "Style" );
13951414
!e1.isNull();
13961415
e1 = e1.nextSiblingElement( "Style" ) )
@@ -1597,13 +1616,16 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
15971616
{
15981617
QgsWmtsTileLayer& l = *it;
15991618

1600-
if ( l.boundingBox.crs.isEmpty() )
1619+
if ( l.boundingBoxes.isEmpty() )
16011620
{
16021621
if ( !detectTileLayerBoundingBox( l ) )
16031622
{
16041623
QgsDebugMsg( "failed to detect bounding box for " + l.identifier + " - using extent of the whole world" );
1605-
l.boundingBox.box = QgsRectangle( -180.0, -90.0, 180.0, 90.0 );
1606-
l.boundingBox.crs = DEFAULT_LATLON_CRS;
1624+
1625+
QgsWmsBoundingBoxProperty bb;
1626+
bb.crs = DEFAULT_LATLON_CRS;
1627+
bb.box = QgsRectangle( -180.0, -90.0, 180.0, 90.0 );
1628+
l.boundingBoxes << bb;
16071629
}
16081630
}
16091631
}
@@ -1699,8 +1721,11 @@ bool QgsWmsCapabilities::detectTileLayerBoundingBox( QgsWmtsTileLayer& l )
16991721
QgsRectangle extent( tm.topLeft, bottomRight );
17001722
extent.normalize();
17011723

1702-
l.boundingBox.box = extent;
1703-
l.boundingBox.crs = tmsIt->crs;
1724+
QgsWmsBoundingBoxProperty bb;
1725+
bb.box = extent;
1726+
bb.crs = crs.authid();
1727+
l.boundingBoxes << bb;
1728+
17041729
return true;
17051730
}
17061731

@@ -1731,9 +1756,9 @@ bool QgsWmsCapabilities::shouldInvertAxisOrientation( const QString& ogcCrs )
17311756

17321757

17331758
QgsWmsCapabilitiesDownload::QgsWmsCapabilitiesDownload( const QString& baseUrl, const QgsWmsAuthorization& auth, QObject *parent )
1734-
: QObject( parent )
1735-
, mBaseUrl( baseUrl )
1736-
, mAuth( auth )
1759+
: QObject( parent )
1760+
, mBaseUrl( baseUrl )
1761+
, mAuth( auth )
17371762
{
17381763
}
17391764

@@ -1764,7 +1789,7 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
17641789
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
17651790

17661791
QEventLoop loop;
1767-
connect(mCapabilitiesReply, SIGNAL(finished()), &loop, SLOT(quit()));
1792+
connect( mCapabilitiesReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
17681793
loop.exec( QEventLoop::ExcludeUserInputEvents );
17691794

17701795
return mError.isEmpty();

0 commit comments

Comments
 (0)
Please sign in to comment.