Skip to content

Commit

Permalink
fix #39068 : geometry_overlays's limit parameter not working as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang authored and nyalldawson committed Oct 21, 2020
1 parent 7854c61 commit 4975965
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -5774,13 +5774,6 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress
QVariant limitValue = node->eval( parent, context );
ENSURE_NO_EVAL_ERROR
qlonglong limit = QgsExpressionUtils::getIntValue( limitValue, parent );
if ( ! isNearestFunc )
{
// for all functions but nearest_neighbour, the limit parameters limits queryset.
// (for nearest_neighbour, it will be used by the spatial index below, which will limit
// but taking distance into account)
request.setLimit( limit );
}

// Fifth parameter (for nearest only) is the max distance
double max_distance = 0;
Expand Down Expand Up @@ -5911,16 +5904,18 @@ static QVariant executeGeomOverlay( const QVariantList &values, const QgsExpress


bool found = false;
int foundCount = 0;
QVariantList results;

QListIterator<QgsFeature> i( features );
while ( i.hasNext() )
while ( i.hasNext() && ( limit == -1 || foundCount < limit ) )
{
QgsFeature feat2 = i.next();

if ( ! relationFunction || ( geometry.*relationFunction )( feat2.geometry() ) ) // Calls the method provided as template argument for the function (e.g. QgsGeometry::intersects)
{
found = true;
foundCount++;

// We just want a single boolean result if there is any intersect: finish and return true
if ( testOnly )
Expand Down

0 comments on commit 4975965

Please sign in to comment.