Skip to content

Commit

Permalink
[WFS provider] Fix #7170 / properly take into account feature count l…
Browse files Browse the repository at this point in the history
…imit (refs #18935)
  • Loading branch information
rouault committed Jun 22, 2018
1 parent b8c11b8 commit 39f0922
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ void QgsWFSFeatureDownloader::run( bool serializeFeatures, int maxFeatures )
success = true;
QgsGmlStreamingParser *parser = mShared->createParser();

if ( maxTotalFeatures > 0 && mTotalDownloadedFeatureCount >= maxTotalFeatures )
{
break;
}
int maxFeaturesThisRequest = static_cast<int>(
std::min( maxTotalFeatures - mTotalDownloadedFeatureCount,
static_cast<qint64>( std::numeric_limits<int>::max() ) ) );
Expand Down
14 changes: 9 additions & 5 deletions src/providers/wfs/qgswfsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,15 +1684,15 @@ bool QgsWFSProvider::getCapabilities()
}

mShared->mWFSVersion = mShared->mCaps.version;
if ( mShared->mURI.maxNumFeatures() > 0 && mShared->mCaps.maxFeatures > 0 )
if ( mShared->mURI.maxNumFeatures() > 0 && mShared->mCaps.maxFeatures > 0 && !( mShared->mCaps.supportsPaging && mShared->mURI.pagingEnabled() ) )
{
mShared->mMaxFeatures = std::min( mShared->mURI.maxNumFeatures(), mShared->mCaps.maxFeatures );
}
else if ( mShared->mURI.maxNumFeatures() > 0 )
{
mShared->mMaxFeatures = mShared->mURI.maxNumFeatures();
}
else if ( mShared->mCaps.maxFeatures > 0 )
else if ( mShared->mCaps.maxFeatures > 0 && !( mShared->mCaps.supportsPaging && mShared->mURI.pagingEnabled() ) )
{
mShared->mMaxFeatures = mShared->mCaps.maxFeatures;
}
Expand All @@ -1705,20 +1705,24 @@ bool QgsWFSProvider::getCapabilities()
{
if ( mShared->mURI.pageSize() > 0 )
{
if ( mShared->mMaxFeatures > 0 )
if ( mShared->mCaps.maxFeatures > 0 )
{
mShared->mPageSize = std::min( mShared->mURI.pageSize(), mShared->mMaxFeatures );
mShared->mPageSize = std::min( mShared->mURI.pageSize(), mShared->mCaps.maxFeatures );
}
else
{
mShared->mPageSize = mShared->mURI.pageSize();
}
}
else if ( mShared->mCaps.maxFeatures > 0 )
{
mShared->mPageSize = mShared->mCaps.maxFeatures;
}
else
{
QgsSettings settings;
mShared->mPageSize = settings.value( QStringLiteral( "wfs/max_feature_count_if_not_provided" ), "1000" ).toInt();
QgsDebugMsg( QString( "Server declares paging but does not advertize max feature count and user did not specify it. Using %1" ).arg( mShared->mMaxFeatures ) );
QgsDebugMsg( QString( "Server declares paging but does not advertize max feature count and user did not specify it. Using %1" ).arg( mShared->mPageSize ) );
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsshareddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ void QgsWFSSharedData::endOfDownload( bool success, int featureCount,
pushError( errorMsgOut );
}

bool bDownloadLimit = truncatedResponse || ( !mCaps.supportsPaging && featureCount == mMaxFeatures && mMaxFeatures > 0 );
bool bDownloadLimit = truncatedResponse || ( featureCount >= mMaxFeatures && mMaxFeatures > 0 );

mDownloadFinished = true;
if ( success && !mRect.isEmpty() )
Expand Down

0 comments on commit 39f0922

Please sign in to comment.