Skip to content
Permalink
Browse files

WMS Server: catch QgsCSException and don't add null bounding boxes to…

… the capabilities
  • Loading branch information
mhugent committed Oct 18, 2016
1 parent 14fbb94 commit 5038949062347615a62e4d656fcacf17dddf87ab
Showing with 42 additions and 11 deletions.
  1. +27 −10 src/server/qgsconfigparserutils.cpp
  2. +15 −1 src/server/qgsserverprojectparser.cpp
@@ -19,6 +19,7 @@
#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransform.h"
#include "qgscsexception.h"
#include "qgsmaplayer.h"
#include "qgsrectangle.h"

@@ -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" );
@@ -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
@@ -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() )
@@ -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"
@@ -722,6 +723,11 @@ void QgsServerProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& gr
continue;

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

if ( !bbox.isEmpty() )
{
if ( firstBBox )
@@ -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;
}

0 comments on commit 5038949

Please sign in to comment.
You can’t perform that action at this time.