Skip to content

Commit 492ee5f

Browse files
committed
Allow to request all atlas features with 'ATLAS_PK=*' if the number is lower than the feature limit
1 parent 2e7bf12 commit 492ee5f

File tree

1 file changed

+59
-41
lines changed

1 file changed

+59
-41
lines changed

src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -396,61 +396,79 @@ namespace QgsWms
396396
QStringLiteral( "The atlas has no coverage layer" ) );
397397
}
398398

399-
QgsAttributeList pkIndexes = cLayer->primaryKeyAttributes();
400-
if ( pkIndexes.size() < 1 )
401-
{
402-
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
403-
QStringLiteral( "An error occurred during the Atlas print" ) );
404-
}
405-
QStringList pkAttributeNames;
406-
for ( int i = 0; i < pkIndexes.size(); ++i )
399+
int maxAtlasFeatures = QgsServerProjectUtils::wmsMaxAtlasFeatures( *mProject );
400+
if ( atlasPk.size() == 1 && atlasPk.at( 0 ) == QStringLiteral( "*" ) )
407401
{
408-
pkAttributeNames.append( cLayer->fields()[pkIndexes.at( i )].name() );
402+
atlas->setFilterFeatures( false );
403+
atlas->updateFeatures();
404+
if ( atlas->count() > maxAtlasFeatures )
405+
{
406+
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
407+
QString( "The project configuration allows to print maximum %1 atlas features at a time" ).arg( maxAtlasFeatures ) );
408+
}
409409
}
410-
411-
int nAtlasFeatures = atlasPk.size() / pkIndexes.size();
412-
if ( nAtlasFeatures * pkIndexes.size() != atlasPk.size() ) //Test is atlasPk.size() is a multiple of pkIndexes.size(). Bail out if not
410+
else
413411
{
414-
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
415-
QStringLiteral( "Wrong number of ATLAS_PK parameters" ) );
416-
}
417-
418-
//number of atlas features might be restricted
419-
int maxAtlasFeatures = QgsServerProjectUtils::wmsMaxAtlasFeatures( *mProject );
420-
nAtlasFeatures = std::min( nAtlasFeatures, maxAtlasFeatures );
412+
QgsAttributeList pkIndexes = cLayer->primaryKeyAttributes();
413+
if ( pkIndexes.size() < 1 )
414+
{
415+
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
416+
QStringLiteral( "An error occurred during the Atlas print" ) );
417+
}
418+
QStringList pkAttributeNames;
419+
for ( int i = 0; i < pkIndexes.size(); ++i )
420+
{
421+
pkAttributeNames.append( cLayer->fields()[pkIndexes.at( i )].name() );
422+
}
421423

422-
QString filterString;
423-
int currentAtlasPk = 0;
424+
int nAtlasFeatures = atlasPk.size() / pkIndexes.size();
425+
if ( nAtlasFeatures * pkIndexes.size() != atlasPk.size() ) //Test is atlasPk.size() is a multiple of pkIndexes.size(). Bail out if not
426+
{
427+
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
428+
QStringLiteral( "Wrong number of ATLAS_PK parameters" ) );
429+
}
424430

425-
for ( int i = 0; i < nAtlasFeatures; ++i )
426-
{
427-
if ( i > 0 )
431+
//number of atlas features might be restricted
432+
if ( nAtlasFeatures > maxAtlasFeatures )
428433
{
429-
filterString.append( " OR " );
434+
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
435+
QString( "%1 atlas features have been requestet, but the project configuration only allows to print %2 atlas features at a time" )
436+
.arg( nAtlasFeatures ).arg( maxAtlasFeatures ) );
430437
}
431438

432-
filterString.append( "( " );
439+
QString filterString;
440+
int currentAtlasPk = 0;
433441

434-
for ( int j = 0; j < pkIndexes.size(); ++j )
442+
for ( int i = 0; i < nAtlasFeatures; ++i )
435443
{
436-
if ( j > 0 )
444+
if ( i > 0 )
437445
{
438-
filterString.append( " AND " );
446+
filterString.append( " OR " );
439447
}
440-
filterString.append( QString( "\"%1\" = %2" ).arg( pkAttributeNames.at( j ) ).arg( atlasPk.at( currentAtlasPk ) ) );
441-
++currentAtlasPk;
442-
}
443448

444-
filterString.append( " )" );
445-
}
449+
filterString.append( "( " );
446450

447-
atlas->setFilterFeatures( true );
448-
QString errorString;
449-
atlas->setFilterExpression( filterString, errorString );
450-
if ( !errorString.isEmpty() )
451-
{
452-
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
453-
QStringLiteral( "An error occurred during the Atlas print" ) );
451+
for ( int j = 0; j < pkIndexes.size(); ++j )
452+
{
453+
if ( j > 0 )
454+
{
455+
filterString.append( " AND " );
456+
}
457+
filterString.append( QString( "\"%1\" = %2" ).arg( pkAttributeNames.at( j ) ).arg( atlasPk.at( currentAtlasPk ) ) );
458+
++currentAtlasPk;
459+
}
460+
461+
filterString.append( " )" );
462+
}
463+
464+
atlas->setFilterFeatures( true );
465+
QString errorString;
466+
atlas->setFilterExpression( filterString, errorString );
467+
if ( !errorString.isEmpty() )
468+
{
469+
throw QgsBadRequestException( QStringLiteral( "AtlasPrintError" ),
470+
QStringLiteral( "An error occurred during the Atlas print" ) );
471+
}
454472
}
455473
}
456474

0 commit comments

Comments
 (0)