Skip to content

Commit

Permalink
WMS Server: catch QgsCSException and don't add null bounding boxes to…
Browse files Browse the repository at this point in the history
… the capabilities
  • Loading branch information
mhugent committed Oct 18, 2016
1 parent 14fbb94 commit 5038949
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/server/qgsconfigparserutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransform.h"
#include "qgscsexception.h"
#include "qgsmaplayer.h"
#include "qgsrectangle.h"

Expand Down Expand Up @@ -95,8 +96,16 @@ void QgsConfigParserUtils::appendLayerBoundingBoxes( QDomElement& layerElem, QDo
if ( !layerExtent.isNull() )
{
QgsCoordinateTransform exGeoTransform( layerCRS, wgs84 );
wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent );
try
{
wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent );
}
catch ( const QgsCsException & )
{
wgs84BoundingRect = QgsRectangle();
}
}

if ( version == "1.1.1" ) // WMS Version 1.1.1
{
ExGeoBBoxElement = doc.createElement( "LatLonBoundingBox" );
Expand Down Expand Up @@ -146,16 +155,19 @@ void QgsConfigParserUtils::appendLayerBoundingBoxes( QDomElement& layerElem, QDo
bBoxElement.setAttribute( "maxy", QString::number( r.yMaximum() ) );
*/

QDomElement lastCRSElem = layerElem.lastChildElement( version == "1.1.1" ? "SRS" : "CRS" );
if ( !lastCRSElem.isNull() )
if ( !wgs84BoundingRect.isNull() ) //LatLonBoundingBox / Ex_GeographicBounding box is optional
{
layerElem.insertAfter( ExGeoBBoxElement, lastCRSElem );
//layerElem.insertAfter( bBoxElement, ExGeoBBoxElement );
}
else
{
layerElem.appendChild( ExGeoBBoxElement );
//layerElem.appendChild( bBoxElement );
QDomElement lastCRSElem = layerElem.lastChildElement( version == "1.1.1" ? "SRS" : "CRS" );
if ( !lastCRSElem.isNull() )
{
layerElem.insertAfter( ExGeoBBoxElement, lastCRSElem );
//layerElem.insertAfter( bBoxElement, ExGeoBBoxElement );
}
else
{
layerElem.appendChild( ExGeoBBoxElement );
//layerElem.appendChild( bBoxElement );
}
}

//In case the number of advertised CRS is constrained
Expand Down Expand Up @@ -195,6 +207,11 @@ void QgsConfigParserUtils::appendLayerBoundingBox( QDomElement& layerElem, QDomD
crsExtent = crsTransform.transformBoundingBox( layerExtent );
}

if ( crsExtent.isNull() )
{
return;
}

//BoundingBox element
QDomElement bBoxElement = doc.createElement( "BoundingBox" );
if ( crs.isValid() )
Expand Down
16 changes: 15 additions & 1 deletion src/server/qgsserverprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "qgsproject.h"
#include "qgsconfigcache.h"
#include "qgsconfigparserutils.h"
#include "qgscsexception.h"
#include "qgsdatasourceuri.h"
#include "qgsmaplayerregistry.h"
#include "qgsmslayercache.h"
Expand Down Expand Up @@ -722,6 +723,11 @@ void QgsServerProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& gr
continue;

QgsRectangle bbox = layerBoundingBoxInProjectCrs( childElem, doc );
if ( bbox.isNull() )
{
continue;
}

if ( !bbox.isEmpty() )
{
if ( firstBBox )
Expand Down Expand Up @@ -895,7 +901,15 @@ QgsRectangle QgsServerProjectParser::layerBoundingBoxInProjectCrs( const QDomEle
QgsCoordinateTransform t( layerCrs, projectCrs() );

//transform
BBox = t.transformBoundingBox( BBox );
try
{
BBox = t.transformBoundingBox( BBox );
}
catch ( const QgsCsException & )
{
BBox = QgsRectangle();
}

return BBox;
}

Expand Down

0 comments on commit 5038949

Please sign in to comment.