Skip to content

Commit cb633ed

Browse files
committedMar 10, 2021
Use the geographicExtent from map layer to avoid an unnecessary computation when possible
1 parent 2e1fb1b commit cb633ed

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed
 

‎src/server/services/wms/qgswmsgetcapabilities.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ namespace QgsWms
6767

6868
void appendLayerBoundingBoxes( QDomDocument &doc, QDomElement &layerElem, const QgsRectangle &lExtent,
6969
const QgsCoordinateReferenceSystem &layerCRS, const QStringList &crsList,
70-
const QStringList &constrainedCrsList, const QgsProject *project );
70+
const QStringList &constrainedCrsList, const QgsProject *project,
71+
const QgsRectangle &geoExtent = QgsRectangle() );
7172

7273
void appendCrsElementToLayer( QDomDocument &doc, QDomElement &layerElement, const QDomElement &precedingElement,
7374
const QString &crsText );
@@ -1094,7 +1095,7 @@ namespace QgsWms
10941095
}
10951096
}
10961097

1097-
appendLayerBoundingBoxes( doc, layerElem, extent, l->crs(), crsList, outputCrsList, project );
1098+
appendLayerBoundingBoxes( doc, layerElem, extent, l->crs(), crsList, outputCrsList, project, l->geographicExtent() );
10981099
}
10991100

11001101
// add details about supported styles of the layer
@@ -1416,7 +1417,8 @@ namespace QgsWms
14161417

14171418
void appendLayerBoundingBoxes( QDomDocument &doc, QDomElement &layerElem, const QgsRectangle &lExtent,
14181419
const QgsCoordinateReferenceSystem &layerCRS, const QStringList &crsList,
1419-
const QStringList &constrainedCrsList, const QgsProject *project )
1420+
const QStringList &constrainedCrsList, const QgsProject *project,
1421+
const QgsRectangle &lGeoExtent )
14201422
{
14211423
if ( layerElem.isNull() )
14221424
{
@@ -1430,29 +1432,31 @@ namespace QgsWms
14301432
layerExtent.grow( 0.000001 );
14311433
}
14321434

1433-
QgsCoordinateReferenceSystem wgs84 = QgsCoordinateReferenceSystem::fromOgcWmsCrs( geoEpsgCrsAuthId() );
1434-
int wgs84precision = 6;
1435-
1436-
QString version = doc.documentElement().attribute( QStringLiteral( "version" ) );
1437-
1438-
//Ex_GeographicBoundingBox
1439-
QDomElement ExGeoBBoxElement;
1440-
//transform the layers native CRS into WGS84
1441-
QgsRectangle wgs84BoundingRect;
1442-
if ( !layerExtent.isNull() )
1435+
QgsRectangle wgs84BoundingRect = lGeoExtent;
1436+
if ( wgs84BoundingRect.isNull() )
14431437
{
1444-
QgsCoordinateTransform exGeoTransform( layerCRS, wgs84, project );
1445-
try
1446-
{
1447-
wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent );
1448-
}
1449-
catch ( const QgsCsException &cse )
1438+
QgsCoordinateReferenceSystem wgs84 = QgsCoordinateReferenceSystem::fromOgcWmsCrs( geoEpsgCrsAuthId() );
1439+
1440+
//transform the layers native CRS into WGS84
1441+
if ( !layerExtent.isNull() )
14501442
{
1451-
QgsMessageLog::logMessage( QStringLiteral( "Error transforming extent: %1" ).arg( cse.what() ), QStringLiteral( "Server" ), Qgis::MessageLevel::Warning );
1452-
wgs84BoundingRect = QgsRectangle();
1443+
QgsCoordinateTransform exGeoTransform( layerCRS, wgs84, project );
1444+
try
1445+
{
1446+
wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent );
1447+
}
1448+
catch ( const QgsCsException &cse )
1449+
{
1450+
QgsMessageLog::logMessage( QStringLiteral( "Error transforming extent: %1" ).arg( cse.what() ), QStringLiteral( "Server" ), Qgis::MessageLevel::Warning );
1451+
wgs84BoundingRect = QgsRectangle();
1452+
}
14531453
}
14541454
}
14551455

1456+
//Ex_GeographicBoundingBox
1457+
int wgs84precision = 6;
1458+
QDomElement ExGeoBBoxElement;
1459+
QString version = doc.documentElement().attribute( QStringLiteral( "version" ) );
14561460
if ( version == QLatin1String( "1.1.1" ) ) // WMS Version 1.1.1
14571461
{
14581462
ExGeoBBoxElement = doc.createElement( QStringLiteral( "LatLonBoundingBox" ) );

0 commit comments

Comments
 (0)
Please sign in to comment.