Skip to content

Commit

Permalink
[Backport release-3_16][Server] Speed up WMS GetCapabilities by remov…
Browse files Browse the repository at this point in the history
…ing featureCount

Backport 803848a from #42409
  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2021
1 parent 4987fb2 commit 7324c92
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -1090,32 +1090,28 @@ namespace QgsWms

//Ex_GeographicBoundingBox
QgsRectangle extent = l->extent(); // layer extent by default
if ( l->type() == QgsMapLayerType::VectorLayer )
if ( extent.isEmpty() )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( l );
if ( vl && vl->featureCount() == 0 )
// if the extent is empty (not only Null), use the wms extent
// defined in the project...
extent = QgsServerProjectUtils::wmsExtent( *project );
if ( extent.isNull() )
{
// if there's no feature, use the wms extent defined in the
// project...
extent = QgsServerProjectUtils::wmsExtent( *project );
if ( extent.isNull() )
// or the CRS extent otherwise
extent = l->crs().bounds();
}
else if ( l->crs() != project->crs() )
{
// If CRS is different transform it to layer's CRS
try
{
// or the CRS extent otherwise
extent = vl->crs().bounds();
QgsCoordinateTransform ct( project->crs(), l->crs(), project->transformContext() );
extent = ct.transform( extent );
}
// If CRS is different transform it to layer's CRS
else if ( vl->crs() != project->crs() )
catch ( QgsCsException &cse )
{
try
{
QgsCoordinateTransform ct( project->crs(), vl->crs(), project->transformContext() );
extent = ct.transform( extent );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QStringLiteral( "Error transforming extent for layer %1: %2" ).arg( vl->name() ).arg( cse.what() ), QStringLiteral( "Server" ), Qgis::MessageLevel::Warning );
continue;
}
QgsMessageLog::logMessage( QStringLiteral( "Error transforming extent for layer %1: %2" ).arg( l->name() ).arg( cse.what() ), QStringLiteral( "Server" ), Qgis::MessageLevel::Warning );
continue;
}
}
}
Expand Down

0 comments on commit 7324c92

Please sign in to comment.